From 52871f006da9af1b727feda6dfae21818b936bf4 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 16 Apr 2025 11:42:48 +0200 Subject: [PATCH] Refactor UserManager dependency injection setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Umbenennung der Methoden für mehr Klarheit: `AddUserManager` zu `AddUserManagerApplication` und `AddInfrastructureServices` zu `AddUserManagerInfrastructure`. Neue Projektreferenzen für `Application`, `Domain` und `Infrastructure` in der `DigitalData.UserManager.DependencyInjection.csproj` hinzugefügt. Einführung von Erweiterungsmethoden in `Extensions.cs`, um die Registrierung von UserManager-Diensten zu rationalisieren und die Kohärenz zwischen Infrastruktur- und Anwendungsdienstregistrierungen zu verbessern. --- .../DIExtensions.cs | 2 +- ...ata.UserManager.DependencyInjection.csproj | 6 ++++ .../Extensions.cs | 33 +++++++++++++++++++ .../DependencyInjection.cs | 10 +++--- 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 DigitalData.UserManager.DependencyInjection/Extensions.cs diff --git a/DigitalData.UserManager.Application/DIExtensions.cs b/DigitalData.UserManager.Application/DIExtensions.cs index 0b96ddf..253dd74 100644 --- a/DigitalData.UserManager.Application/DIExtensions.cs +++ b/DigitalData.UserManager.Application/DIExtensions.cs @@ -16,7 +16,7 @@ namespace DigitalData.UserManager.Application /// The type of the DbContext to use for the repositories. /// The IServiceCollection to which the services will be added. /// The updated IServiceCollection. - public static IServiceCollection AddUserManager(this IServiceCollection services) + public static IServiceCollection AddUserManagerApplication(this IServiceCollection services) => services .AddAutoMapper(typeof(UserMappingProfile).Assembly) .AddAutoMapper(typeof(GroupMappingProfile).Assembly) diff --git a/DigitalData.UserManager.DependencyInjection/DigitalData.UserManager.DependencyInjection.csproj b/DigitalData.UserManager.DependencyInjection/DigitalData.UserManager.DependencyInjection.csproj index 9ba033b..0c14929 100644 --- a/DigitalData.UserManager.DependencyInjection/DigitalData.UserManager.DependencyInjection.csproj +++ b/DigitalData.UserManager.DependencyInjection/DigitalData.UserManager.DependencyInjection.csproj @@ -18,4 +18,10 @@ 1.0.0 + + + + + + diff --git a/DigitalData.UserManager.DependencyInjection/Extensions.cs b/DigitalData.UserManager.DependencyInjection/Extensions.cs new file mode 100644 index 0000000..f6b17d3 --- /dev/null +++ b/DigitalData.UserManager.DependencyInjection/Extensions.cs @@ -0,0 +1,33 @@ +using DigitalData.UserManager.Application; +using DigitalData.UserManager.Infrastructure; +using DigitalData.UserManager.Infrastructure.Contracts; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace DigitalData.UserManager.DependencyInjection; + +public static class Extensions +{ + public static IServiceCollection AddUserManager(this IServiceCollection services) + where TDbContext : DbContext, IUserManagerDbContext + { + services.AddUserManagerInfrastructure(); + services.AddUserManagerApplication(); + return services; + } + + public static IServiceCollection AddUserManager(this IServiceCollection services, Action optionsAction) + { + services.AddUserManagerInfrastructure(optionsAction); + services.AddUserManagerApplication(); + return services; + } + + public static IServiceCollection AddUserManager(this IServiceCollection services, string connectionString) + where TDbContext : DbContext, IUserManagerDbContext + { + services.AddUserManagerInfrastructure(connectionString); + services.AddUserManagerApplication(); + return services; + } +} diff --git a/DigitalData.UserManager.Infrastructure/DependencyInjection.cs b/DigitalData.UserManager.Infrastructure/DependencyInjection.cs index 4a66700..cbcf498 100644 --- a/DigitalData.UserManager.Infrastructure/DependencyInjection.cs +++ b/DigitalData.UserManager.Infrastructure/DependencyInjection.cs @@ -16,7 +16,7 @@ public static class DependencyInjection /// The type of the DbContext to use for the repositories. /// The IServiceCollection to which the services will be added. /// The updated IServiceCollection. - public static IServiceCollection AddInfrastructureServices(this IServiceCollection services) + public static IServiceCollection AddUserManagerInfrastructure(this IServiceCollection services) where TDbContext : DbContext, IUserManagerDbContext { return services @@ -36,9 +36,9 @@ public static class DependencyInjection /// The to which the services will be added. /// An to configure the . /// The updated . - public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action optionsAction) => services + public static IServiceCollection AddUserManagerInfrastructure(this IServiceCollection services, Action optionsAction) => services .AddDbContext(optionsAction) - .AddInfrastructureServices(); + .AddUserManagerInfrastructure(); /// /// Adds the UserManager services and repositories to the specified . @@ -46,6 +46,6 @@ public static class DependencyInjection /// /// The IServiceCollection to which the services will be added. /// The updated IServiceCollection. - public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, string connectionString) => services - .AddInfrastructureServices(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging()); + public static IServiceCollection AddUserManagerInfrastructure(this IServiceCollection services, string connectionString) => services + .AddUserManagerInfrastructure(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging()); }