@@ -19,7 +19,8 @@ public static class ServiceCollectionExtensions
1919 /// </summary>
2020 /// <typeparam name="TContext"> The type of <see cref="DbContext"/> to add. </typeparam>
2121 /// <param name="services"> The <see cref="IServiceCollection"/> instance. </param>
22- /// <param name="setup"> Optional action to configure the <see cref="PostgresContextFactory"/> (section name, prefix, pool size, etc). </param>
22+ /// <param name="setup"> Optional action to configure the <see cref="PostgresOptionsBuilder"/> (section name, prefix, pool size, etc). </param>
23+ /// <param name="setupContextOptions"> Optional action to configure the <see cref="DbContextOptionsBuilder"/> (e.g. enable sensitive data logging). </param>
2324 /// <returns> Current <see cref="IServiceCollection"/> instance. </returns>
2425 /// <exception cref="KeyNotFoundException"> When required database settings are missing. </exception>
2526 /// <example>
@@ -28,16 +29,17 @@ public static class ServiceCollectionExtensions
2829 /// </code>
2930 /// </example>
3031 public static IServiceCollection AddPostgresDbContext < TContext > ( this IServiceCollection services ,
31- Action < PostgresContextFactory > ? setup = null ) where TContext : DbContext
32+ Action < PostgresOptionsBuilder > ? setup = null , Action < DbContextOptionsBuilder > ? setupContextOptions = null ) where TContext : DbContext
3233 {
33- PostgresContextFactory contextFactory = new ( ) ;
34+ PostgresOptionsBuilder contextFactory = new ( ) ;
3435 setup ? . Invoke ( contextFactory ) ;
3536
3637 services . AddDbContext < TContext > ( ( sp , builder ) =>
3738 {
3839 var configuration = sp . GetRequiredService < IConfiguration > ( ) ;
3940 string connectionString = BuildConnectionString ( configuration , contextFactory ) ;
4041 builder . UseNpgsql ( connectionString ) ;
42+ setupContextOptions ? . Invoke ( builder ) ;
4143 if ( contextFactory . UseLazyLoadingProxies )
4244 {
4345 builder . UseLazyLoadingProxies ( ) ;
@@ -51,7 +53,7 @@ public static IServiceCollection AddPostgresDbContext<TContext>(this IServiceCol
5153 return services ;
5254 }
5355
54- private static string BuildConnectionString ( IConfiguration configuration , PostgresContextFactory contextFactory )
56+ private static string BuildConnectionString ( IConfiguration configuration , PostgresOptionsBuilder contextFactory )
5557 {
5658 bool isDevelopment = GetIsDevelopment ( configuration ) ;
5759 var settings = configuration . GetSection ( contextFactory . ConfigurationSection ) ;
@@ -82,7 +84,7 @@ private static string BuildConnectionString(IConfiguration configuration, Postgr
8284 return builder . ConnectionString ;
8385 }
8486
85- private static string ? TryGetSetting ( IConfigurationSection settings , string key , IConfiguration configuration , PostgresContextFactory contextFactory )
87+ private static string ? TryGetSetting ( IConfigurationSection settings , string key , IConfiguration configuration , PostgresOptionsBuilder contextFactory )
8688 {
8789 if ( configuration [ contextFactory . ConfigurationPrefix + key ] is string value )
8890 {
@@ -95,7 +97,7 @@ private static string BuildConnectionString(IConfiguration configuration, Postgr
9597 return settings [ key ] ;
9698 }
9799
98- private static string GetSetting ( IConfigurationSection settings , string key , IConfiguration configuration , PostgresContextFactory contextFactory )
100+ private static string GetSetting ( IConfigurationSection settings , string key , IConfiguration configuration , PostgresOptionsBuilder contextFactory )
99101 {
100102 if ( configuration [ contextFactory . ConfigurationPrefix + key ] is string value )
101103 {
0 commit comments