@@ -13,15 +13,11 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
13
13
{
14
14
services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
15
15
16
- services . AddTransient ( s =>
16
+ services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
17
17
{
18
18
var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
19
19
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 ) ) ;
25
21
} ) ;
26
22
services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
27
23
}
@@ -30,15 +26,11 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
30
26
{
31
27
services . AssertNotAlreadyRegistered ( typeof ( IRepository < > ) ) ;
32
28
33
- services . AddTransient ( s =>
29
+ services . AddDbContextPool < BlogDbContext > ( ( s , options ) =>
34
30
{
35
31
var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
36
32
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 ) ;
42
34
} ) ;
43
35
services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
44
36
}
0 commit comments