Release v1.0.0 #16
.envDbInitializer.csDependencyInjection.cs
.gitea/workflows
ApiDto
ApiDto.csproj
Backend.slnCommon
Requests
Configuration
ScheduleRequest.csResponses
Endpoint
Common
Attributes
BadRequestResponseAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
Services
Configuration
EnvironmentManager.cs
General
Swagger
Controllers
BaseController.cs
Endpoint.csprojConfiguration
V1
CampusController.csDisciplineController.csFacultyController.csGroupController.csLectureHallController.csProfessorController.csScheduleController.cs
WeatherForecastController.csMiddleware
Program.csWeatherForecast.csSecurity
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
Schedule
Interfaces
Domain
Domain.csproj
Schedule
Persistence
Common
Contexts
Schedule
EntityTypeConfigurations
Mark.cs
Persistence.csprojUberDbContext.csSqlite
22
SqlData/Persistence/Common/DbContextFactory.cs
Normal file
22
SqlData/Persistence/Common/DbContextFactory.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Persistence.Common;
|
||||
|
||||
public static class DbContextFactory
|
||||
{
|
||||
public static DbContextOptionsBuilder CreateDbContext<TDbContext, TEntity>(this DbContextOptionsBuilder options, DatabaseProvider provider)
|
||||
where TDbContext : BaseDbContext<TDbContext>
|
||||
where TEntity : class
|
||||
{
|
||||
var dbContext = (TDbContext)Activator.CreateInstance(typeof(TDbContext), (DbContextOptions<TDbContext>)options.Options)!;
|
||||
var configurationType = ConfigurationResolver.GetConfigurationType<TEntity>(provider);
|
||||
var configurationInstance = (IEntityTypeConfiguration<TEntity>)Activator.CreateInstance(configurationType)!;
|
||||
|
||||
var modelBuilder = new ModelBuilder();
|
||||
modelBuilder.ApplyConfiguration(configurationInstance);
|
||||
dbContext.ApplyConfigurations(modelBuilder);
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user