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