Refactor UserManager dependency injection setup
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.
This commit is contained in:
parent
ac064f4671
commit
52871f006d
@ -16,7 +16,7 @@ namespace DigitalData.UserManager.Application
|
|||||||
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
|
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
|
||||||
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
||||||
/// <returns>The updated IServiceCollection.</returns>
|
/// <returns>The updated IServiceCollection.</returns>
|
||||||
public static IServiceCollection AddUserManager(this IServiceCollection services)
|
public static IServiceCollection AddUserManagerApplication(this IServiceCollection services)
|
||||||
=> services
|
=> services
|
||||||
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
|
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
|
||||||
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
|
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
|
||||||
|
|||||||
@ -18,4 +18,10 @@
|
|||||||
<FileVersion>1.0.0</FileVersion>
|
<FileVersion>1.0.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DigitalData.UserManager.Application\DigitalData.UserManager.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\DigitalData.UserManager.Domain\DigitalData.UserManager.Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\DigitalData.UserManager.Infrastructure\DigitalData.UserManager.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
33
DigitalData.UserManager.DependencyInjection/Extensions.cs
Normal file
33
DigitalData.UserManager.DependencyInjection/Extensions.cs
Normal file
@ -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<TDbContext>(this IServiceCollection services)
|
||||||
|
where TDbContext : DbContext, IUserManagerDbContext
|
||||||
|
{
|
||||||
|
services.AddUserManagerInfrastructure<TDbContext>();
|
||||||
|
services.AddUserManagerApplication();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddUserManager(this IServiceCollection services, Action<DbContextOptionsBuilder> optionsAction)
|
||||||
|
{
|
||||||
|
services.AddUserManagerInfrastructure(optionsAction);
|
||||||
|
services.AddUserManagerApplication();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services, string connectionString)
|
||||||
|
where TDbContext : DbContext, IUserManagerDbContext
|
||||||
|
{
|
||||||
|
services.AddUserManagerInfrastructure(connectionString);
|
||||||
|
services.AddUserManagerApplication();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ public static class DependencyInjection
|
|||||||
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
|
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
|
||||||
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
||||||
/// <returns>The updated IServiceCollection.</returns>
|
/// <returns>The updated IServiceCollection.</returns>
|
||||||
public static IServiceCollection AddInfrastructureServices<TDbContext>(this IServiceCollection services)
|
public static IServiceCollection AddUserManagerInfrastructure<TDbContext>(this IServiceCollection services)
|
||||||
where TDbContext : DbContext, IUserManagerDbContext
|
where TDbContext : DbContext, IUserManagerDbContext
|
||||||
{
|
{
|
||||||
return services
|
return services
|
||||||
@ -36,9 +36,9 @@ public static class DependencyInjection
|
|||||||
/// <param name="services">The <see cref="IServiceCollection"/> to which the services will be added.</param>
|
/// <param name="services">The <see cref="IServiceCollection"/> to which the services will be added.</param>
|
||||||
/// <param name="optionsAction">An <see cref="Action{T}"/> to configure the <see cref="DbContextOptionsBuilder"/>.</param>
|
/// <param name="optionsAction">An <see cref="Action{T}"/> to configure the <see cref="DbContextOptionsBuilder"/>.</param>
|
||||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action<DbContextOptionsBuilder> optionsAction) => services
|
public static IServiceCollection AddUserManagerInfrastructure(this IServiceCollection services, Action<DbContextOptionsBuilder> optionsAction) => services
|
||||||
.AddDbContext<UserManagerDbContext>(optionsAction)
|
.AddDbContext<UserManagerDbContext>(optionsAction)
|
||||||
.AddInfrastructureServices<UserManagerDbContext>();
|
.AddUserManagerInfrastructure<UserManagerDbContext>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
|
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
|
||||||
@ -46,6 +46,6 @@ public static class DependencyInjection
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
/// <param name="services">The IServiceCollection to which the services will be added.</param>
|
||||||
/// <returns>The updated IServiceCollection.</returns>
|
/// <returns>The updated IServiceCollection.</returns>
|
||||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, string connectionString) => services
|
public static IServiceCollection AddUserManagerInfrastructure(this IServiceCollection services, string connectionString) => services
|
||||||
.AddInfrastructureServices(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging());
|
.AddUserManagerInfrastructure(options => options.UseSqlServer(connectionString).EnableSensitiveDataLogging());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user