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

51 lines
1.8 KiB
C#
Raw Permalink 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 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);
services.AddScoped<IApplicationDBExamContext>(provider => provider.GetService<ApplicationDBExamContext>());
2023-06-05 20:22:51 +07:00
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
}