MireaBackend/SqlData/Persistence/DependencyInjection.cs

40 lines
2.2 KiB
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
namespace Mirea.Api.DataAccess.Persistence;
public static class DependencyInjection
{
public static IServiceCollection AddPersistence(this IServiceCollection services, 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<UberDbContext>(DbConfig);
services.AddScoped<ICampusDbContext>(provider => provider.GetService<CampusDbContext>()!);
services.AddScoped<IDisciplineDbContext>(provider => provider.GetService<DisciplineDbContext>()!);
services.AddScoped<IFacultyDbContext>(provider => provider.GetService<FacultyDbContext>()!);
services.AddScoped<IGroupDbContext>(provider => provider.GetService<GroupDbContext>()!);
services.AddScoped<ILectureHallDbContext>(provider => provider.GetService<LectureHallDbContext>()!);
services.AddScoped<ILessonAssociationDbContext>(provider => provider.GetService<LessonAssociationDbContext>()!);
services.AddScoped<IProfessorDbContext>(provider => provider.GetService<ProfessorDbContext>()!);
services.AddScoped<ILessonDbContext>(provider => provider.GetService<LessonDbContext>()!);
services.AddScoped<ITypeOfOccupationDbContext>(provider => provider.GetService<TypeOfOccupationDbContext>()!);
2024-05-19 11:52:56 +03:00
services.AddScoped<ISpecificWeekDbContext>(provider => provider.GetService<SpecificWeekDbContext>()!);
return services;
void DbConfig(DbContextOptionsBuilder options) => options.UseSqlite(connection);
}
}