@@ -13,11 +13,15 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
1313 {
1414 services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
1515
16- services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
16+ services . AddTransient ( s =>
1717 {
1818 var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
1919 var connectionString = configuration . ConnectionString ;
20- options . UseSqlServer ( connectionString , options => options . EnableRetryOnFailure ( 3 , TimeSpan . FromSeconds ( 30 ) , null ) ) ;
20+ var dbOptions = new DbContextOptionsBuilder < BlogDbContext > ( )
21+ . UseSqlServer ( connectionString , options => options . EnableRetryOnFailure ( 3 , TimeSpan . FromSeconds ( 30 ) , null ) )
22+ . Options ;
23+
24+ return new PooledDbContextFactory < BlogDbContext > ( dbOptions ) . CreateDbContext ( ) ;
2125 } ) ;
2226 services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
2327 }
@@ -26,11 +30,15 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
2630 {
2731 services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
2832
29- services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
33+ services . AddTransient ( s =>
3034 {
3135 var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
3236 var connectionString = configuration . ConnectionString ;
33- options . UseSqlite ( connectionString ) ;
37+ var dbOptions = new DbContextOptionsBuilder < BlogDbContext > ( )
38+ . UseSqlite ( connectionString )
39+ . Options ;
40+
41+ return new PooledDbContextFactory < BlogDbContext > ( dbOptions ) . CreateDbContext ( ) ;
3442 } ) ;
3543 services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
3644 }
0 commit comments