using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Npgsql; namespace Persistence.Database.Model; public static class DependencyInjection { public static IServiceCollection AddPersistenceDbContext(this IServiceCollection services, IConfiguration configuration) { string connectionStringName = "DefaultConnection"; services.AddDbContext(options => { var dataSourceBuilder = new NpgsqlDataSourceBuilder(configuration.GetConnectionString(connectionStringName)); dataSourceBuilder.EnableDynamicJson(); options.UseNpgsql(dataSourceBuilder.Build()); }); services.AddScoped(provider => provider.GetRequiredService()); return services; } }