Dbcontext umbenannt. DIExtention für modelBuilder hinzugefügt, um OnModelCreating zu verwenden.

This commit is contained in:
Developer 02 2024-06-13 13:29:55 +02:00
parent d2dc116cd0
commit 8faed31baa
10 changed files with 71 additions and 57 deletions

View File

@ -38,10 +38,6 @@ try {
options.LogoutPath = "/api/auth/logout"; options.LogoutPath = "/api/auth/logout";
}); });
builder.Services.AddDbContext<DDECMDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DD_ECM_Connection"))
.EnableDetailedErrors());
var allowedOrigins = builder.Configuration.GetSection("AllowedOrigins").Get<string[]>() ?? throw new InvalidOperationException("In appsettings there is no allowed origin."); var allowedOrigins = builder.Configuration.GetSection("AllowedOrigins").Get<string[]>() ?? throw new InvalidOperationException("In appsettings there is no allowed origin.");
builder.Services.AddCors(options => builder.Services.AddCors(options =>
@ -57,7 +53,9 @@ try {
}); });
//builder.Services.AddAutoMapper(typeof(DirectoryMappingProfile).Assembly); //builder.Services.AddAutoMapper(typeof(DirectoryMappingProfile).Assembly);
builder.Services.AddUserManager(); builder.Services.AddUserManager(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DD_ECM_Connection"))
.EnableDetailedErrors());
builder.Services.AddDirectorySearchService(); builder.Services.AddDirectorySearchService();

View File

@ -3,6 +3,7 @@ using DigitalData.UserManager.Application.MappingProfiles;
using DigitalData.UserManager.Application.Services; using DigitalData.UserManager.Application.Services;
using DigitalData.UserManager.Infrastructure.Contracts; using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Infrastructure.Repositories; using DigitalData.UserManager.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.UserManager.Application namespace DigitalData.UserManager.Application
@ -17,7 +18,8 @@ namespace DigitalData.UserManager.Application
/// </remarks> /// </remarks>
/// <param name="services">The IServiceCollection to add services to.</param> /// <param name="services">The IServiceCollection to add services to.</param>
/// <returns>The updated IServiceCollection.</returns> /// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager(this IServiceCollection services) => services public static IServiceCollection AddUserManager(this IServiceCollection services, Action<DbContextOptionsBuilder>? optionsAction) => services
.AddDbContext<UserManagerDbContext>(optionsAction: optionsAction)
.AddAutoMapper(typeof(UserMappingProfile).Assembly) .AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly) .AddAutoMapper(typeof(GroupMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupOfUserMappingProfile).Assembly) .AddAutoMapper(typeof(GroupOfUserMappingProfile).Assembly)

View File

@ -1,39 +1,35 @@
using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Domain.Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure
{ {
public class DDECMDbContext : DbContext public static class DbContextExtensions
{ {
public DDECMDbContext(DbContextOptions<DDECMDbContext> options) : base(options) public static ModelBuilder ConfigureUserManager(this ModelBuilder modelBuilder)
{ {
} modelBuilder.Entity<User>()
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_DEL"))
protected override void OnModelCreating(ModelBuilder modelBuilder) .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_INS"))
{ .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD"))
modelBuilder.Entity<User>() .ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD_LOG"));
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_DEL"))
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_INS")) modelBuilder.Entity<GroupOfUser>()
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD")) .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_DEL"))
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD_LOG")); .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_UPD"));
modelBuilder.Entity<GroupOfUser>() modelBuilder.Entity<Group>()
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_DEL")) .ToTable(tb => tb.HasTrigger("TBDD_GROUPS_AFT_UPD"))
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_UPD")); .HasKey(group => group.Guid);
modelBuilder.Entity<Group>() modelBuilder.Entity<Module>()
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_AFT_UPD")) .ToTable(tb => tb.HasTrigger("TBDD_MODULE_AFT_UPD"));
.HasKey(group => group.Guid);
modelBuilder.Entity<ModuleOfUser>();
modelBuilder.Entity<Module>()
.ToTable(tb => tb.HasTrigger("TBDD_MODULE_AFT_UPD")); modelBuilder.Entity<UserRep>()
.ToTable(tb => tb.HasTrigger("TBDD_USER_REPRESENTATION_AFT_UPD"));
modelBuilder.Entity<ModuleOfUser>();
return modelBuilder;
modelBuilder.Entity<UserRep>() }
.ToTable(tb => tb.HasTrigger("TBDD_USER_REPRESENTATION_AFT_UPD")); }
}
base.OnModelCreating(modelBuilder);
}
}
}

View File

@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class GroupOfUserRepository : CRUDRepository<GroupOfUser, int, DDECMDbContext>, IGroupOfUserRepository public class GroupOfUserRepository : CRUDRepository<GroupOfUser, int, UserManagerDbContext>, IGroupOfUserRepository
{ {
public GroupOfUserRepository(DDECMDbContext dbContext) : base(dbContext) public GroupOfUserRepository(UserManagerDbContext dbContext) : base(dbContext)
{ {
} }

View File

@ -4,9 +4,9 @@ using DigitalData.UserManager.Infrastructure.Contracts;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class GroupRepository : CRUDRepository<Group, int, DDECMDbContext>, IGroupRepository public class GroupRepository : CRUDRepository<Group, int, UserManagerDbContext>, IGroupRepository
{ {
public GroupRepository(DDECMDbContext dbContext) : base(dbContext) public GroupRepository(UserManagerDbContext dbContext) : base(dbContext)
{ {
} }
} }

View File

@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class ModuleOfUserRepository : CRUDRepository<ModuleOfUser, int, DDECMDbContext>, IModuleOfUserRepository public class ModuleOfUserRepository : CRUDRepository<ModuleOfUser, int, UserManagerDbContext>, IModuleOfUserRepository
{ {
public ModuleOfUserRepository(DDECMDbContext dbContext) : base(dbContext) public ModuleOfUserRepository(UserManagerDbContext dbContext) : base(dbContext)
{ {
} }

View File

@ -4,9 +4,9 @@ using DigitalData.UserManager.Infrastructure.Contracts;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class ModuleRepository : CRUDRepository<Module, int, DDECMDbContext>, IModuleRepository public class ModuleRepository : CRUDRepository<Module, int, UserManagerDbContext>, IModuleRepository
{ {
public ModuleRepository(DDECMDbContext dbContext) : base(dbContext) public ModuleRepository(UserManagerDbContext dbContext) : base(dbContext)
{ {
} }
} }

View File

@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class UserRepRepository : CRUDRepository<UserRep, int, DDECMDbContext>, IUserRepRepository public class UserRepRepository : CRUDRepository<UserRep, int, UserManagerDbContext>, IUserRepRepository
{ {
public UserRepRepository(DDECMDbContext dbContext) : base(dbContext) public UserRepRepository(UserManagerDbContext dbContext) : base(dbContext)
{ {
} }

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
{ {
public class UserRepository : CRUDRepository<User, int, DDECMDbContext>, IUserRepository public class UserRepository : CRUDRepository<User, int, UserManagerDbContext>, IUserRepository
{ {
private IModuleOfUserRepository _moduleOfUserRepo; private IModuleOfUserRepository _moduleOfUserRepo;
private IGroupOfUserRepository _groupOfUserRepo; private IGroupOfUserRepository _groupOfUserRepo;
public UserRepository(DDECMDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo) : base(dbContext) public UserRepository(UserManagerDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo) : base(dbContext)
{ {
_moduleOfUserRepo = moduleOfUserRepo; _moduleOfUserRepo = moduleOfUserRepo;
_groupOfUserRepo = groupOfUserRepo; _groupOfUserRepo = groupOfUserRepo;

View File

@ -0,0 +1,18 @@
using DigitalData.UserManager.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories
{
public class UserManagerDbContext : DbContext
{
public UserManagerDbContext(DbContextOptions<UserManagerDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureUserManager();
base.OnModelCreating(modelBuilder);
}
}
}