Refactor DIExtensions.AddUserManager to Use Generic TDbContext for Improved Flexibility.

This commit is contained in:
Developer 02
2024-06-13 13:44:51 +02:00
parent 8faed31baa
commit 43c98f9454
9 changed files with 39 additions and 30 deletions

View File

@@ -11,15 +11,15 @@ namespace DigitalData.UserManager.Application
public static class DIExtensions
{
/// <summary>
/// Extension method to configure dependency injection for the UserManager application.
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
/// This method registers the necessary mappings, repositories, and services for the UserManager.
/// </summary>
/// <remarks>
/// This method registers AutoMapper profiles, repositories, and services for the UserManager application.
/// </remarks>
/// <param name="services">The IServiceCollection to add services to.</param>
/// <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>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager(this IServiceCollection services, Action<DbContextOptionsBuilder>? optionsAction) => services
.AddDbContext<UserManagerDbContext>(optionsAction: optionsAction)
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext
=> services
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupOfUserMappingProfile).Assembly)
@@ -27,12 +27,12 @@ namespace DigitalData.UserManager.Application
.AddAutoMapper(typeof(ModuleOfUserMappingProfile).Assembly)
.AddAutoMapper(typeof(UserRepMappingProfile).Assembly)
.AddScoped<IUserRepository, UserRepository>()
.AddScoped<IGroupRepository, GroupRepository>()
.AddScoped<IGroupOfUserRepository, GroupOfUserRepository>()
.AddScoped<IModuleRepository, ModuleRepository>()
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository>()
.AddScoped<IUserRepRepository, UserRepRepository>()
.AddScoped<IUserRepository, UserRepository<TDbContext>>()
.AddScoped<IGroupRepository, GroupRepository<TDbContext>>()
.AddScoped<IGroupOfUserRepository, GroupOfUserRepository<TDbContext>>()
.AddScoped<IModuleRepository, ModuleRepository<TDbContext>>()
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository<TDbContext>>()
.AddScoped<IUserRepRepository, UserRepRepository<TDbContext>>()
.AddScoped<IUserService, UserService>()
.AddScoped<IGroupService, GroupService>()