shuffles code with DependencyInjection namespace, forgot to commit changes to Startup

This commit is contained in:
Shannon
2020-12-23 12:02:01 +11:00
parent ac7fac8f56
commit 7115e0a11e
19 changed files with 132 additions and 221 deletions

View File

@@ -12,7 +12,7 @@ using Umbraco.Core.DependencyInjection;
using Umbraco.Extensions;
using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.Common.DependencyInjection;
namespace Umbraco.Tests.Integration
{
@@ -37,7 +37,6 @@ namespace Umbraco.Tests.Integration
/// <summary>
/// Calling AddUmbracoCore to configure the container and UseUmbracoCore to start the runtime
/// </summary>
/// <returns></returns>
[Test]
public async Task UseUmbracoCore()
{

View File

@@ -4,7 +4,7 @@ using Umbraco.Core.Cache;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Runtime;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.Common.DependencyInjection;
namespace Umbraco.Tests.Integration.TestServerTest
{
@@ -13,8 +13,6 @@ namespace Umbraco.Tests.Integration.TestServerTest
/// <summary>
/// Uses a test version of Umbraco Core with a test IRuntime
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IUmbracoBuilder AddTestCore(this IUmbracoBuilder builder, TestHelper testHelper)
{
builder.AddUmbracoCore();

View File

@@ -19,8 +19,9 @@ using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;
using Umbraco.Web;
using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.BackOffice.DependencyInjection;
using Umbraco.Web.Common.Controllers;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.Common.DependencyInjection;
using Umbraco.Web.Website.Controllers;
namespace Umbraco.Tests.Integration.TestServerTest

View File

@@ -16,7 +16,6 @@ using NUnit.Framework;
using Serilog;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.IO;
@@ -31,7 +30,8 @@ using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Tests.Testing;
using Umbraco.Web;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.BackOffice.DependencyInjection;
using Umbraco.Web.Common.DependencyInjection;
namespace Umbraco.Tests.Integration.Testing
{
@@ -400,7 +400,7 @@ namespace Umbraco.Tests.Integration.Testing
public IConfiguration Configuration { get; protected set; }
public TestHelper TestHelper = new TestHelper();
public TestHelper TestHelper { get; } = new TestHelper();
protected virtual Action<IServiceCollection> CustomTestSetup => services => { };

View File

@@ -3,8 +3,8 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Umbraco.Core.Security;
using Umbraco.Extensions;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Web.BackOffice.DependencyInjection;
using Umbraco.Web.Common.Security;
namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice

View File

@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Umbraco.Core;
using Umbraco.Core.Security;
using Umbraco.Core.Serialization;
using Umbraco.Extensions;
using Umbraco.Net;
using Umbraco.Web.Actions;
using Umbraco.Web.BackOffice.Authorization;
@@ -13,15 +14,13 @@ using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Common.Authorization;
using Umbraco.Web.Common.Security;
namespace Umbraco.Extensions
namespace Umbraco.Web.BackOffice.DependencyInjection
{
public static class BackOfficeServiceCollectionExtensions
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the services required for using Umbraco back office Identity
/// </summary>
/// <param name="services"></param>
public static void AddUmbracoBackOfficeIdentity(this IServiceCollection services)
{
services.AddDataProtection();
@@ -79,12 +78,10 @@ namespace Umbraco.Extensions
/// <summary>
/// Add authorization handlers and policies
/// </summary>
/// <param name="services"></param>
public static void AddBackOfficeAuthorizationPolicies(this IServiceCollection services, string backOfficeAuthenticationScheme = Constants.Security.BackOfficeAuthenticationType)
{
// NOTE: Even though we are registering these handlers globally they will only actually execute their logic for
// any auth defining a matching requirement and scheme.
// any auth defining a matching requirement and scheme.
services.AddSingleton<IAuthorizationHandler, BackOfficeHandler>();
services.AddSingleton<IAuthorizationHandler, TreeHandler>();
services.AddSingleton<IAuthorizationHandler, SectionHandler>();
@@ -247,7 +244,7 @@ namespace Umbraco.Extensions
policy.Requirements.Add(new SectionRequirement(Constants.Applications.Settings));
});
//We will not allow the tree to render unless the user has access to any of the sections that the tree gets rendered
// We will not allow the tree to render unless the user has access to any of the sections that the tree gets rendered
// this is not ideal but until we change permissions to be tree based (not section) there's not much else we can do here.
options.AddPolicy(AuthorizationPolicies.SectionAccessForContentTree, policy =>
{

View File

@@ -1,16 +1,20 @@
using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core.DependencyInjection;
using Umbraco.Infrastructure.PublishedCache.Extensions;
using Umbraco.Web.BackOffice.Authorization;
using Umbraco.Web.BackOffice.Security;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.BackOffice.Trees;
using Umbraco.Web.Common.Authorization;
using Umbraco.Web.Common.DependencyInjection;
namespace Umbraco.Extensions
namespace Umbraco.Web.BackOffice.DependencyInjection
{
/// <summary>
/// Extension methods for <see cref="IUmbracoBuilder"/> for the Umbraco back office
/// </summary>
public static class BackOfficeUmbracoBuilderExtensions
public static partial class UmbracoBuilderExtensions
{
/// <summary>
/// Adds all required components to run the Umbraco back office
@@ -76,14 +80,15 @@ namespace Umbraco.Extensions
/// <summary>
/// Adds Umbraco back office authorization policies
/// </summary>
public static IUmbracoBuilder AddBackOfficeAuthorizationPolicies(this IUmbracoBuilder builder, string backOfficeAuthenticationScheme = Umbraco.Core.Constants.Security.BackOfficeAuthenticationType)
public static IUmbracoBuilder AddBackOfficeAuthorizationPolicies(this IUmbracoBuilder builder, string backOfficeAuthenticationScheme = Core.Constants.Security.BackOfficeAuthenticationType)
{
builder.Services.AddBackOfficeAuthorizationPolicies(backOfficeAuthenticationScheme);
// TODO: See other TODOs in things like UmbracoApiControllerBase ... AFAIK all of this is only used for the back office
// so IMO these controllers and the features auth policies should just be moved to the back office project and then this
// ext method can be removed.
builder.Services.AddUmbracoCommonAuthorizationPolicies();
builder.Services.AddSingleton<IAuthorizationHandler, FeatureAuthorizeHandler>();
builder.Services.AddAuthorization(options
=> options.AddPolicy(AuthorizationPolicies.UmbracoFeatureEnabled, policy
=> policy.Requirements.Add(new FeatureAuthorizeRequirement())));
return builder;
}
@@ -97,5 +102,20 @@ namespace Umbraco.Extensions
return builder;
}
/// <summary>
/// Adds support for external login providers in Umbraco
/// </summary>
public static IUmbracoBuilder AddBackOfficeExternalLogins(this IUmbracoBuilder umbracoBuilder, Action<BackOfficeExternalLoginsBuilder> builder)
{
builder(new BackOfficeExternalLoginsBuilder(umbracoBuilder.Services));
return umbracoBuilder;
}
/// <summary>
/// Gets the back office tree collection builder
/// </summary>
public static TreeCollectionBuilder Trees(this IUmbracoBuilder builder)
=> builder.WithCollectionBuilder<TreeCollectionBuilder>();
}
}

View File

@@ -1,16 +0,0 @@
using System;
using Umbraco.Core.DependencyInjection;
using Umbraco.Web.BackOffice.Security;
namespace Umbraco.Extensions
{
public static class AuthenticationBuilderExtensions
{
public static IUmbracoBuilder AddBackOfficeExternalLogins(this IUmbracoBuilder umbracoBuilder, Action<BackOfficeExternalLoginsBuilder> builder)
{
builder(new BackOfficeExternalLoginsBuilder(umbracoBuilder.Services));
return umbracoBuilder;
}
}
}

View File

@@ -1,29 +0,0 @@
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Web.BackOffice.Trees;
// the namespace here is intentional - although defined in Umbraco.Web assembly,
// this class should be visible when using Umbraco.Core.Components, alongside
// Umbraco.Core's own CompositionExtensions class
// ReSharper disable once CheckNamespace
namespace Umbraco.Extensions
{
/// <summary>
/// Provides extension methods to the <see cref="Composition"/> class.
/// </summary>
public static class WebCompositionExtensions
{
#region Collection Builders
/// <summary>
/// Gets the back office tree collection builder
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static TreeCollectionBuilder Trees(this IUmbracoBuilder builder)
=> builder.WithCollectionBuilder<TreeCollectionBuilder>();
#endregion
}
}

View File

@@ -4,15 +4,20 @@ using Umbraco.Core.Security;
namespace Umbraco.Extensions
{
/// <summary>
/// Extension methods for <see cref="IdentityBuilder"/>
/// </summary>
public static class IdentityBuilderExtensions
{
/// <summary>
/// Adds a <see cref="UserManager{TUser}"/> implementation for <seealso cref="BackOfficeIdentityUser"/>
/// </summary>
/// <typeparam name="TUserManager">The type of the user manager to add.</typeparam>
/// <typeparam name="TInterface"></typeparam>
/// <typeparam name="TInterface">The usermanager interface</typeparam>
/// <typeparam name="TUserManager">The usermanager type</typeparam>
/// <param name="identityBuilder">The <see cref="IdentityBuilder"/></param>
/// <returns>The current <see cref="IdentityBuilder"/> instance.</returns>
public static IdentityBuilder AddUserManager<TInterface, TUserManager>(this IdentityBuilder identityBuilder) where TUserManager : UserManager<BackOfficeIdentityUser>, TInterface
public static IdentityBuilder AddUserManager<TInterface, TUserManager>(this IdentityBuilder identityBuilder)
where TUserManager : UserManager<BackOfficeIdentityUser>, TInterface
{
identityBuilder.AddUserManager<TUserManager>();
identityBuilder.Services.AddScoped(typeof(TInterface), typeof(TUserManager));
@@ -22,11 +27,12 @@ namespace Umbraco.Extensions
/// <summary>
/// Adds a <see cref="SignInManager{TUser}"/> implementation for <seealso cref="BackOfficeIdentityUser"/>
/// </summary>
/// <typeparam name="TInterface"></typeparam>
/// <typeparam name="TSignInManager"></typeparam>
/// <param name="identityBuilder"></param>
/// <returns></returns>
public static IdentityBuilder AddSignInManager<TInterface, TSignInManager>(this IdentityBuilder identityBuilder) where TSignInManager : SignInManager<BackOfficeIdentityUser>, TInterface
/// <typeparam name="TInterface">The sign in manager interface</typeparam>
/// <typeparam name="TSignInManager">The sign in manager type</typeparam>
/// <param name="identityBuilder">The <see cref="IdentityBuilder"/></param>
/// <returns>The current <see cref="IdentityBuilder"/> instance.</returns>
public static IdentityBuilder AddSignInManager<TInterface, TSignInManager>(this IdentityBuilder identityBuilder)
where TSignInManager : SignInManager<BackOfficeIdentityUser>, TInterface
{
identityBuilder.AddSignInManager<TSignInManager>();
identityBuilder.Services.AddScoped(typeof(TInterface), typeof(TSignInManager));

View File

@@ -1,14 +1,15 @@
using System.Linq;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Core;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Services;
using Umbraco.Extensions;
using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.BackOffice.DependencyInjection;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.BackOffice.Middleware;
using Umbraco.Web.BackOffice.Routing;

View File

@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Web.Common.Filters;
using Umbraco.Web.Common.ModelBinders;
namespace Umbraco.Web.Common.AspNetCore
{
/// <summary>
/// Options for globally configuring MVC for Umbraco
/// </summary>
/// <remarks>
/// We generally don't want to change the global MVC settings since we want to be unobtrusive as possible but some
/// global mods are needed - so long as they don't interfere with normal user usages of MVC.
/// </remarks>
public class UmbracoMvcConfigureOptions : IConfigureOptions<MvcOptions>
{
/// <inheritdoc/>
public void Configure(MvcOptions options)
{
options.ModelBinderProviders.Insert(0, new ContentModelBinderProvider());
options.Filters.Insert(0, new EnsurePartialViewMacroViewContextFilterAttribute());
}
}
}

View File

@@ -1,37 +1,22 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Web.Caching;
using SixLabors.ImageSharp.Web.Commands;
using SixLabors.ImageSharp.Web.DependencyInjection;
using SixLabors.ImageSharp.Web.Processors;
using SixLabors.ImageSharp.Web.Providers;
using Smidge;
using Smidge.Nuglify;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Configuration.Models.Validation;
using Umbraco.Web.Common.ApplicationModels;
namespace Umbraco.Extensions
namespace Umbraco.Web.Common.DependencyInjection
{
public static class UmbracoWebServiceCollectionExtensions
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds Image Sharp with Umbraco settings
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <returns></returns>
public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services, IConfiguration configuration)
{
var imagingSettings = configuration.GetSection(Core.Constants.Configuration.ConfigImaging)
@@ -50,7 +35,7 @@ namespace Umbraco.Extensions
return Task.CompletedTask;
};
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
options.OnProcessedAsync = _ => Task.CompletedTask;
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
})
@@ -70,7 +55,6 @@ namespace Umbraco.Extensions
return services;
}
private static void RemoveIntParamenterIfValueGreatherThen(IDictionary<string, string> commands, string parameter, int maxValue)
{
if (commands.TryGetValue(parameter, out var command))
@@ -84,30 +68,5 @@ namespace Umbraco.Extensions
}
}
}
/// <summary>
/// Options for globally configuring MVC for Umbraco
/// </summary>
/// <remarks>
/// We generally don't want to change the global MVC settings since we want to be unobtrusive as possible but some
/// global mods are needed - so long as they don't interfere with normal user usages of MVC.
/// </remarks>
public class UmbracoMvcConfigureOptions : IConfigureOptions<MvcOptions>
{
// TODO: we can inject params with DI here
public UmbracoMvcConfigureOptions()
{
}
// TODO: we can configure global mvc options here if we need to
public void Configure(MvcOptions options)
{
}
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
@@ -7,7 +8,6 @@ using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
@@ -36,21 +36,19 @@ using Umbraco.Infrastructure.HostedServices.ServerRegistration;
using Umbraco.Infrastructure.Runtime;
using Umbraco.Web.Common.ApplicationModels;
using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.Common.Filters;
using Umbraco.Web.Common.ModelBinders;
using Umbraco.Web.Common.DependencyInjection;
using Umbraco.Web.Common.Profiler;
using Umbraco.Web.Telemetry;
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
namespace Umbraco.Web.Common.Extensions
namespace Umbraco.Web.Common.DependencyInjection
{
// TODO: We could add parameters to configure each of these for flexibility
/// <summary>
/// Extension methods for <see cref="IUmbracoBuilder"/> for the common Umbraco functionality
/// </summary>
public static class UmbracoBuilderExtensions
public static partial class UmbracoBuilderExtensions
{
public static IUmbracoBuilder AddUmbraco(
this IServiceCollection services,
@@ -90,11 +88,15 @@ namespace Umbraco.Web.Common.Extensions
return new UmbracoBuilder(services, config, typeLoader, loggerFactory);
}
/// <remarks>Composes Composers</remarks>
/// <summary>
/// Adds core Umbraco services
/// </summary>
public static IUmbracoBuilder AddUmbracoCore(this IUmbracoBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddLazySupport();
@@ -163,15 +165,21 @@ namespace Umbraco.Web.Common.Extensions
return builder;
}
/// <summary>
/// Adds Umbraco composers for plugins
/// </summary>
public static IUmbracoBuilder AddComposers(this IUmbracoBuilder builder)
{
var composerTypes = builder.TypeLoader.GetTypes<IComposer>();
var enableDisable = builder.TypeLoader.GetAssemblyAttributes(typeof(EnableComposerAttribute), typeof(DisableComposerAttribute));
IEnumerable<Type> composerTypes = builder.TypeLoader.GetTypes<IComposer>();
IEnumerable<Attribute> enableDisable = builder.TypeLoader.GetAssemblyAttributes(typeof(EnableComposerAttribute), typeof(DisableComposerAttribute));
new Composers(builder, composerTypes, enableDisable, builder.BuilderLoggerFactory.CreateLogger<Composers>()).Compose();
return builder;
}
/// <summary>
/// Add Umbraco configuration services and options
/// </summary>
public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder)
{
// Register configuration validators.
@@ -208,6 +216,9 @@ namespace Umbraco.Web.Common.Extensions
return builder;
}
/// <summary>
/// Add Umbraco hosted services
/// </summary>
public static IUmbracoBuilder AddHostedServices(this IUmbracoBuilder builder)
{
builder.Services.AddHostedService<HealthCheckNotifier>();
@@ -221,40 +232,44 @@ namespace Umbraco.Web.Common.Extensions
return builder;
}
// TODO: Not sure this needs to exist and/or be public?
public static IUmbracoBuilder AddHttpClients(this IUmbracoBuilder builder)
{
builder.Services.AddHttpClient();
return builder;
}
/// <summary>
/// Adds mini profiler services for Umbraco
/// </summary>
public static IUmbracoBuilder AddMiniProfiler(this IUmbracoBuilder builder)
{
builder.Services.AddMiniProfiler(options =>
{
options.ShouldProfile = request => false; // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile
});
// WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile
options.ShouldProfile = request => false);
return builder;
}
public static IUmbracoBuilder AddMvcAndRazor(this IUmbracoBuilder builder, Action<MvcOptions> mvcOptions = null, Action<IMvcBuilder> mvcBuilding = null)
public static IUmbracoBuilder AddMvcAndRazor(this IUmbracoBuilder builder, Action<IMvcBuilder> mvcBuilding = null)
{
// TODO: We need to figure out if we can work around this because calling AddControllersWithViews modifies the global app and order is very important
// this will directly affect developers who need to call that themselves.
// We need to have runtime compilation of views when using umbraco. We could consider having only this when a specific config is set.
// But as far as I can see, there are still precompiled views, even when this is activated, so maybe it is okay.
var mvcBuilder = builder.Services.AddControllersWithViews(options =>
{
options.ModelBinderProviders.Insert(0, new ContentModelBinderProvider());
IMvcBuilder mvcBuilder = builder.Services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
options.Filters.Insert(0, new EnsurePartialViewMacroViewContextFilterAttribute());
mvcOptions?.Invoke(options);
}).AddRazorRuntimeCompilation();
mvcBuilding?.Invoke(mvcBuilder);
return builder;
}
/// <summary>
/// Add runtime minifier support for Umbraco
/// </summary>
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
{
builder.Services.AddSmidge(builder.Config.GetSection(Core.Constants.Configuration.ConfigRuntimeMinification));
@@ -274,7 +289,7 @@ namespace Umbraco.Web.Common.Extensions
options.Cookie.HttpOnly = true;
});
builder.Services.ConfigureOptions<UmbracoWebServiceCollectionExtensions.UmbracoMvcConfigureOptions>();
builder.Services.ConfigureOptions<UmbracoMvcConfigureOptions>();
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, UmbracoApiBehaviorApplicationModelProvider>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, BackOfficeApplicationModelProvider>());
builder.Services.AddUmbracoImageSharp(builder.Config);
@@ -282,9 +297,10 @@ namespace Umbraco.Web.Common.Extensions
return builder;
}
// TODO: Does this need to exist and/or be public?
public static IUmbracoBuilder AddWebServer(this IUmbracoBuilder builder)
{
// TODO: We need to figure out why thsi is needed and fix those endpoints to not need them, we don't want to change global things
// TODO: We need to figure out why this is needed and fix those endpoints to not need them, we don't want to change global things
// If using Kestrel: https://stackoverflow.com/a/55196057
builder.Services.Configure<KestrelServerOptions>(options =>
{

View File

@@ -14,7 +14,6 @@ using Umbraco.Core.Hosting;
using Umbraco.Infrastructure.Logging.Serilog.Enrichers;
using Umbraco.Web.Common.Middleware;
using Umbraco.Web.Common.Plugins;
using Umbraco.Web.PublishedCache.NuCache;
namespace Umbraco.Extensions
{

View File

@@ -1,25 +0,0 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Web.BackOffice.Authorization;
using Umbraco.Web.Common.Authorization;
namespace Umbraco.Extensions
{
public static class ServiceCollectionExtensions
{
public static void AddUmbracoCommonAuthorizationPolicies(this IServiceCollection services)
{
// TODO: Should this only exist in the back office project? These really are only ever used for the back office AFAIK
// If it is moved it should only target the back office scheme
services.AddSingleton<IAuthorizationHandler, FeatureAuthorizeHandler>();
services.AddAuthorization(options =>
{
options.AddPolicy(AuthorizationPolicies.UmbracoFeatureEnabled, policy =>
policy.Requirements.Add(new FeatureAuthorizeRequirement()));
});
}
}
}

View File

@@ -4,8 +4,12 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Core.DependencyInjection;
using Microsoft.Identity.Web;
using Umbraco.Extensions;
using Umbraco.Web.BackOffice.DependencyInjection;
using Umbraco.Web.BackOffice.Security;
using Umbraco.Web.Common.DependencyInjection;
using Umbraco.Web.Website.DependencyInjection;
namespace Umbraco.Web.UI.NetCore
{
@@ -29,6 +33,7 @@ namespace Umbraco.Web.UI.NetCore
}
/// <summary>
/// Configures the services
/// </summary>
@@ -40,10 +45,11 @@ namespace Umbraco.Web.UI.NetCore
{
#pragma warning disable IDE0022 // Use expression body for methods
services.AddUmbraco(_env, _config)
.AddAllBackOfficeComponents()
.AddUmbracoWebsite()
.AddBackOffice()
.AddWebsite()
.Build();
#pragma warning restore IDE0022 // Use expression body for methods
}
/// <summary>

View File

@@ -1,7 +1,6 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SixLabors.ImageSharp.Web.DependencyInjection;
using Umbraco.Web.Website.Routing;
namespace Umbraco.Extensions

View File

@@ -1,44 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Core.DependencyInjection;
using Umbraco.Infrastructure.PublishedCache.Extensions;
using Umbraco.Web.Website.Controllers;
using Umbraco.Web.Website.Routing;
using Umbraco.Web.Website.ViewEngines;
namespace Umbraco.Extensions
{
/// <summary>
/// <see cref="IUmbracoBuilder"/> extensions for umbraco front-end website
/// </summary>
public static class WebsiteUmbracoBuilderExtensions
{
/// <summary>
/// Add services for the umbraco front-end website
/// </summary>
public static IUmbracoBuilder AddWebsite(this IUmbracoBuilder builder)
{
// Set the render & plugin view engines (Super complicated, but this allows us to use the IServiceCollection
// to inject dependencies into the viewEngines)
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, RenderMvcViewOptionsSetup>();
builder.Services.AddSingleton<IRenderViewEngine, RenderViewEngine>();
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, PluginMvcViewOptionsSetup>();
builder.Services.AddSingleton<IPluginViewEngine, PluginViewEngine>();
// Wraps all existing view engines in a ProfilerViewEngine
builder.Services.AddTransient<IConfigureOptions<MvcViewOptions>, ProfilingViewEngineWrapperMvcViewOptionsSetup>();
// TODO figure out if we need more to work on load balanced setups
builder.Services.AddDataProtection();
builder.Services.AddScoped<UmbracoRouteValueTransformer>();
builder.Services.AddSingleton<IUmbracoRenderingDefaults, UmbracoRenderingDefaults>();
builder.AddNuCache();
return builder;
}
}
}