Dbcontext umbenannt. DIExtention für modelBuilder hinzugefügt, um OnModelCreating zu verwenden.
This commit is contained in:
parent
d2dc116cd0
commit
8faed31baa
@ -38,10 +38,6 @@ try {
|
||||
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.");
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
@ -57,7 +53,9 @@ try {
|
||||
});
|
||||
|
||||
//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();
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ using DigitalData.UserManager.Application.MappingProfiles;
|
||||
using DigitalData.UserManager.Application.Services;
|
||||
using DigitalData.UserManager.Infrastructure.Contracts;
|
||||
using DigitalData.UserManager.Infrastructure.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.UserManager.Application
|
||||
@ -17,7 +18,8 @@ namespace DigitalData.UserManager.Application
|
||||
/// </remarks>
|
||||
/// <param name="services">The IServiceCollection to add services to.</param>
|
||||
/// <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(GroupMappingProfile).Assembly)
|
||||
.AddAutoMapper(typeof(GroupOfUserMappingProfile).Assembly)
|
||||
|
||||
@ -1,39 +1,35 @@
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
{
|
||||
public class DDECMDbContext : DbContext
|
||||
{
|
||||
public DDECMDbContext(DbContextOptions<DDECMDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<User>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_DEL"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_INS"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD_LOG"));
|
||||
|
||||
modelBuilder.Entity<GroupOfUser>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_DEL"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_UPD"));
|
||||
|
||||
modelBuilder.Entity<Group>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_AFT_UPD"))
|
||||
.HasKey(group => group.Guid);
|
||||
|
||||
modelBuilder.Entity<Module>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_MODULE_AFT_UPD"));
|
||||
|
||||
modelBuilder.Entity<ModuleOfUser>();
|
||||
|
||||
modelBuilder.Entity<UserRep>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_REPRESENTATION_AFT_UPD"));
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DigitalData.UserManager.Infrastructure
|
||||
{
|
||||
public static class DbContextExtensions
|
||||
{
|
||||
public static ModelBuilder ConfigureUserManager(this ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<User>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_DEL"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_INS"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_AFT_UPD_LOG"));
|
||||
|
||||
modelBuilder.Entity<GroupOfUser>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_DEL"))
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_USER_AFT_UPD"));
|
||||
|
||||
modelBuilder.Entity<Group>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_GROUPS_AFT_UPD"))
|
||||
.HasKey(group => group.Guid);
|
||||
|
||||
modelBuilder.Entity<Module>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_MODULE_AFT_UPD"));
|
||||
|
||||
modelBuilder.Entity<ModuleOfUser>();
|
||||
|
||||
modelBuilder.Entity<UserRep>()
|
||||
.ToTable(tb => tb.HasTrigger("TBDD_USER_REPRESENTATION_AFT_UPD"));
|
||||
|
||||
return modelBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ using DigitalData.UserManager.Infrastructure.Contracts;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ using DigitalData.UserManager.Infrastructure.Contracts;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
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 IGroupOfUserRepository _groupOfUserRepo;
|
||||
public UserRepository(DDECMDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo) : base(dbContext)
|
||||
public UserRepository(UserManagerDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo) : base(dbContext)
|
||||
{
|
||||
_moduleOfUserRepo = moduleOfUserRepo;
|
||||
_groupOfUserRepo = groupOfUserRepo;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user