hrms-api-backend/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs

97 lines
3.6 KiB
C#
Raw Normal View History

2023-06-05 20:22:51 +07:00
using BMA.EHR.Application.Common.Interfaces;
2023-07-05 10:22:42 +07:00
using BMA.EHR.Application.Repositories;
2023-06-05 20:22:51 +07:00
using BMA.EHR.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BMA.EHR.Infrastructure
{
2023-10-08 13:54:20 +07:00
public static class InfrastructureServiceRegistration
{
public static IServiceCollection AddLeavePersistence(this IServiceCollection services,
IConfiguration configuration)
{
// leave db context
var connectionStringLeave = configuration.GetConnectionString("LeaveConnection");
services.AddDbContext<LeaveDbContext>(options =>
options.UseMySql(connectionStringLeave, ServerVersion.AutoDetect(connectionStringLeave),
b =>
{
b.MigrationsAssembly(typeof(LeaveDbContext).Assembly.FullName);
b.MigrationsHistoryTable("__LeaveMigrationsHistory");
}),
ServiceLifetime.Transient);
services.AddScoped<ILeaveDbContext>(provider => provider.GetService<LeaveDbContext>());
return services;
}
public static IServiceCollection AddDisciplinePersistence(this IServiceCollection services,
IConfiguration configuration)
{
// discipline db context
var connectionStringDiscipline = configuration.GetConnectionString("DisciplineConnection");
services.AddDbContext<DisciplineDbContext>(options =>
options.UseMySql(connectionStringDiscipline, ServerVersion.AutoDetect(connectionStringDiscipline),
b =>
{
b.MigrationsAssembly(typeof(DisciplineDbContext).Assembly.FullName);
b.MigrationsHistoryTable("__DisciplineMigrationsHistory");
}),
ServiceLifetime.Transient);
services.AddScoped<IDisciplineDbContext>(provider => provider.GetService<DisciplineDbContext>());
return services;
}
2023-10-08 13:54:20 +07:00
public static IServiceCollection AddPersistence(this IServiceCollection services,
IConfiguration configuration)
2023-07-05 10:22:42 +07:00
{
services.AddTransient<MinIOService>();
2023-10-08 13:54:20 +07:00
2023-07-05 10:22:42 +07:00
var connectionString = configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<ApplicationDBContext>(options =>
2023-10-08 13:54:20 +07:00
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString),
b =>
{
b.MigrationsAssembly(typeof(ApplicationDBContext).Assembly.FullName);
b.MigrationsHistoryTable("__EHRMigrationsHistory");
}),
ServiceLifetime.Transient);
services.AddScoped<IApplicationDBContext>(provider => provider.GetService<ApplicationDBContext>());
var connectionStringExam = configuration.GetConnectionString("ExamConnection");
services.AddDbContext<ApplicationDBExamContext>(options =>
options.UseMySql(connectionStringExam, ServerVersion.AutoDetect(connectionStringExam),
b =>
{
b.MigrationsAssembly(typeof(ApplicationDBExamContext).Assembly.FullName);
b.MigrationsHistoryTable("__EHRMigrationsHistory");
}),
ServiceLifetime.Transient);
2023-11-16 13:17:54 +07:00
services.AddScoped<IApplicationDBExamContext>(provider => provider.GetService<ApplicationDBExamContext>());
2023-10-08 13:54:20 +07:00
return services;
}
2023-06-25 18:36:02 +07:00
2023-10-08 13:54:20 +07:00
}
2023-06-05 20:22:51 +07:00
}