@@ -13,15 +13,11 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
1313 {
1414 services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
1515
16- services . AddTransient ( s =>
16+ services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
1717 {
1818 var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
1919 var connectionString = configuration . ConnectionString ;
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 ( ) ;
20+ options . UseSqlServer ( connectionString , options => options . EnableRetryOnFailure ( 3 , TimeSpan . FromSeconds ( 30 ) , null ) ) ;
2521 } ) ;
2622 services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
2723 }
@@ -30,15 +26,11 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
3026 {
3127 services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
3228
33- services . AddTransient ( s =>
29+ services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
3430 {
3531 var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
3632 var connectionString = configuration . ConnectionString ;
37- var dbOptions = new DbContextOptionsBuilder < BlogDbContext > ( )
38- . UseSqlite ( connectionString )
39- . Options ;
40-
41- return new PooledDbContextFactory < BlogDbContext > ( dbOptions ) . CreateDbContext ( ) ;
33+ options . UseSqlite ( connectionString ) ;
4234 } ) ;
4335 services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
4436 }
0 commit comments