2024-11-15 16:29:15 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-11-26 14:19:16 +05:00
|
|
|
|
using Npgsql;
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
|
|
namespace Persistence.Database.Model;
|
|
|
|
|
|
|
|
|
|
public static class DependencyInjection
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddPersistenceDbContext(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
string connectionStringName = "DefaultConnection";
|
|
|
|
|
|
2024-11-26 14:19:16 +05:00
|
|
|
|
services.AddDbContext<PersistenceDbContext>(options =>
|
|
|
|
|
{
|
|
|
|
|
var dataSourceBuilder = new NpgsqlDataSourceBuilder(configuration.GetConnectionString(connectionStringName));
|
|
|
|
|
dataSourceBuilder.EnableDynamicJson();
|
|
|
|
|
options.UseNpgsql(dataSourceBuilder.Build());
|
|
|
|
|
});
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
|
|
services.AddScoped<DbContext>(provider => provider.GetRequiredService<PersistenceDbContext>());
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|