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
@ -1,24 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||
using Mirea.Api.DataAccess.Persistence.Common;
|
||||
using Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Persistence;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddPersistence(this IServiceCollection services, string connection)
|
||||
public static IServiceCollection AddPersistence(this IServiceCollection services, DatabaseProvider dbProvider, string connection)
|
||||
{
|
||||
services.AddDbContext<CampusDbContext>(DbConfig);
|
||||
services.AddDbContext<DisciplineDbContext>(DbConfig);
|
||||
services.AddDbContext<FacultyDbContext>(DbConfig);
|
||||
services.AddDbContext<GroupDbContext>(DbConfig);
|
||||
services.AddDbContext<LectureHallDbContext>(DbConfig);
|
||||
services.AddDbContext<LessonAssociationDbContext>(DbConfig);
|
||||
services.AddDbContext<ProfessorDbContext>(DbConfig);
|
||||
services.AddDbContext<LessonDbContext>(DbConfig);
|
||||
services.AddDbContext<TypeOfOccupationDbContext>(DbConfig);
|
||||
services.AddDbContext<SpecificWeekDbContext>(DbConfig);
|
||||
services.AddDbContext<CampusDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<CampusDbContext, Campus>(dbProvider));
|
||||
services.AddDbContext<DisciplineDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<DisciplineDbContext, Discipline>(dbProvider));
|
||||
services.AddDbContext<FacultyDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<FacultyDbContext, Faculty>(dbProvider));
|
||||
services.AddDbContext<GroupDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<GroupDbContext, Group>(dbProvider));
|
||||
services.AddDbContext<LectureHallDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<LectureHallDbContext, LectureHall>(dbProvider));
|
||||
services.AddDbContext<LessonAssociationDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<LessonAssociationDbContext, LessonAssociation>(dbProvider));
|
||||
services.AddDbContext<ProfessorDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<ProfessorDbContext, Professor>(dbProvider));
|
||||
services.AddDbContext<LessonDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<LessonDbContext, Lesson>(dbProvider));
|
||||
services.AddDbContext<TypeOfOccupationDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<TypeOfOccupationDbContext, TypeOfOccupation>(dbProvider));
|
||||
services.AddDbContext<SpecificWeekDbContext>(options =>
|
||||
UseDatabase(options).CreateDbContext<SpecificWeekDbContext, SpecificWeek>(dbProvider));
|
||||
|
||||
|
||||
services.AddDbContext<UberDbContext>(DbConfig);
|
||||
|
||||
@ -35,6 +52,15 @@ public static class DependencyInjection
|
||||
|
||||
return services;
|
||||
|
||||
void DbConfig(DbContextOptionsBuilder options) => options.UseSqlite(connection);
|
||||
DbContextOptionsBuilder UseDatabase(DbContextOptionsBuilder options)
|
||||
{
|
||||
return dbProvider switch
|
||||
{
|
||||
DatabaseProvider.Sqlite => options.UseSqlite(connection),
|
||||
DatabaseProvider.Mysql => options.UseMySql(connection, ServerVersion.AutoDetect(connection)),
|
||||
DatabaseProvider.Postgresql => options.UseNpgsql(connection),
|
||||
_ => throw new ArgumentException("Unsupported database provider", Enum.GetName(dbProvider))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user