2024-11-15 16:29:15 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.Database.Model;
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
|
|
public static class DependencyInjection
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddPersistenceDbContext(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
string connectionStringName = "DefaultConnection";
|
|
|
|
|
|
2024-11-26 15:07:18 +05:00
|
|
|
|
services.AddDbContext<PersistencePostgresContext>(options =>
|
2024-12-03 17:05:46 +05:00
|
|
|
|
options.UseNpgsql(configuration.GetConnectionString(connectionStringName)));
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
2024-11-26 15:07:18 +05:00
|
|
|
|
services.AddScoped<DbContext>(provider => provider.GetRequiredService<PersistencePostgresContext>());
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|