Add Application configuration #11

Merged
Wesser merged 128 commits from feat/add-setup into release/v1.0.0 2024-06-01 07:35:30 +03:00
Showing only changes of commit 271df127a6 - Show all commits

View File

@ -36,8 +36,28 @@ public static class DependencyInjection
services.AddDbContext<SpecificWeekDbContext>(options =>
UseDatabase(options).CreateDbContext<SpecificWeekDbContext, SpecificWeek>(dbProvider));
services.AddDbContext<UberDbContext>(options =>
{
var providerNamespace = typeof(Mark).Namespace + "." + Enum.GetName(dbProvider);
services.AddDbContext<UberDbContext>(DbConfig);
var assembly = Assembly.GetExecutingAssembly();
var configurationTypes = assembly.GetTypes()
.Where(t =>
t is { IsNested: false, IsAbstract: false, Namespace: not null } &&
t.Namespace.StartsWith(providerNamespace) &&
t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)));
var modelBuilder = new ModelBuilder();
foreach (var configurationType in configurationTypes)
{
var configurationInstance = Activator.CreateInstance(configurationType)!;
modelBuilder.ApplyConfiguration(configurationInstance);
}
var dbContext = (UberDbContext)Activator.CreateInstance(typeof(UberDbContext), (DbContextOptions<UberDbContext>)UseDatabase(options).Options)!;
dbContext.ApplyConfigurations(modelBuilder);
});
services.AddScoped<ICampusDbContext>(provider => provider.GetRequiredService<CampusDbContext>());
services.AddScoped<IDisciplineDbContext>(provider => provider.GetRequiredService<DisciplineDbContext>());