Пример #1
0
        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);
        }
Пример #2
0
 public void AddContextSettings(PostgresContextSettings postgresContextSettings)
 {
     PostgresContextSettings = postgresContextSettings;
 }