From aaab486c5269dc778baa1bbd2dcdcd1d99f79919 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 2 Sep 2021 09:50:13 +0200 Subject: [PATCH 1/3] Added SetBackOfficeUserManager extension method to IUmbracoBuilder --- .../UmbracoApplicationBuilder.Identity.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs new file mode 100644 index 0000000000..fd6f0be482 --- /dev/null +++ b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Security; + +namespace Umbraco.Extensions +{ + public static partial class UmbracoApplicationBuilderExtensions + { + public static IUmbracoBuilder SetBackOfficeUserManager(this IUmbracoBuilder builder) + where TUserManager : UserManager, IBackOfficeUserManager + { + + var customType = typeof(TUserManager); + var userManagerType = typeof(UserManager); + builder.Services.Replace(ServiceDescriptor.Scoped(typeof(IBackOfficeUserManager),customType)); + builder.Services.AddScoped(customType, services => services.GetRequiredService(userManagerType)); + builder.Services.Replace(ServiceDescriptor.Scoped(userManagerType,customType)); + return builder; + } + } +} From 2254d475bdebe3a4b1ce46d501e0a193a374d3f5 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 3 Sep 2021 08:35:13 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Mole --- .../Extensions/UmbracoApplicationBuilder.Identity.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs index fd6f0be482..d456c39fcb 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs @@ -12,11 +12,11 @@ namespace Umbraco.Extensions where TUserManager : UserManager, IBackOfficeUserManager { - var customType = typeof(TUserManager); - var userManagerType = typeof(UserManager); - builder.Services.Replace(ServiceDescriptor.Scoped(typeof(IBackOfficeUserManager),customType)); + Type customType = typeof(TUserManager); + Type userManagerType = typeof(UserManager); + builder.Services.Replace(ServiceDescriptor.Scoped(typeof(IBackOfficeUserManager), customType)); builder.Services.AddScoped(customType, services => services.GetRequiredService(userManagerType)); - builder.Services.Replace(ServiceDescriptor.Scoped(userManagerType,customType)); + builder.Services.Replace(ServiceDescriptor.Scoped(userManagerType, customType)); return builder; } } From 9787ea0cfa58762c5b448b8789960c3ff9da3ef6 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 3 Sep 2021 08:42:22 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- .../Extensions/UmbracoApplicationBuilder.Identity.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs index d456c39fcb..64fde06ac8 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoApplicationBuilder.Identity.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions;