persistence/DD.Persistence.Database.Postgres/DependencyInjection.cs

21 lines
712 B
C#
Raw Permalink Normal View History

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