2
2
using LinkDotNet . Blog . Infrastructure . Persistence ;
3
3
using LinkDotNet . Blog . Infrastructure . Persistence . Sql ;
4
4
using Microsoft . EntityFrameworkCore ;
5
+ using Microsoft . EntityFrameworkCore . Infrastructure ;
5
6
using Microsoft . Extensions . DependencyInjection ;
6
7
7
8
namespace LinkDotNet . Blog . Web . RegistrationExtensions ;
@@ -16,11 +17,11 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
16
17
{
17
18
var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
18
19
var connectionString = configuration . ConnectionString ;
19
- var dbOptions = new DbContextOptionsBuilder ( )
20
+ var dbOptions = new DbContextOptionsBuilder < BlogDbContext > ( )
20
21
. UseSqlServer ( connectionString , options => options . EnableRetryOnFailure ( 3 , TimeSpan . FromSeconds ( 30 ) , null ) )
21
22
. Options ;
22
23
23
- return new BlogDbContext ( dbOptions ) ;
24
+ return new PooledDbContextFactory < BlogDbContext > ( dbOptions ) . CreateDbContext ( ) ;
24
25
} ) ;
25
26
services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
26
27
}
@@ -33,11 +34,11 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
33
34
{
34
35
var configuration = s . GetService < AppConfiguration > ( ) ?? throw new NullReferenceException ( nameof ( AppConfiguration ) ) ;
35
36
var connectionString = configuration . ConnectionString ;
36
- var dbOptions = new DbContextOptionsBuilder ( )
37
+ var dbOptions = new DbContextOptionsBuilder < BlogDbContext > ( )
37
38
. UseSqlite ( connectionString )
38
39
. Options ;
39
40
40
- return new BlogDbContext ( dbOptions ) ;
41
+ return new PooledDbContextFactory < BlogDbContext > ( dbOptions ) . CreateDbContext ( ) ;
41
42
} ) ;
42
43
services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
43
44
}
0 commit comments