public static IServiceCollection IncludePostgres <T>(this IServiceCollection services, PostgresSettings postgresSettings, PostgresContextSettings postgresContextSettings, bool shouldAddEntityFrameworkNpgsql = false) where T : DbContext { postgresSettings.AddContextSettings(postgresContextSettings); services .AddScoped(provider => postgresSettings) .AddDbContext <T>(options => options.UseNpgsql(postgresSettings.ConnectionString)); if (shouldAddEntityFrameworkNpgsql) { services.AddEntityFrameworkNpgsql(); } return(services); }
public void AddContextSettings(PostgresContextSettings postgresContextSettings) { PostgresContextSettings = postgresContextSettings; }