50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace BMA.EHR.Infrastructure
|
|
{
|
|
public static class InfrastructureServiceRegistration
|
|
{
|
|
public static IServiceCollection AddPersistence(this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
services.AddTransient<MinIOService>();
|
|
|
|
|
|
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
|
|
|
services.AddDbContext<ApplicationDBContext>(options =>
|
|
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<IApplicationDBContext>(provider => provider.GetService<ApplicationDBExamContext>());
|
|
|
|
return services;
|
|
}
|
|
|
|
}
|
|
}
|