Skip to content

Commit 82c7804

Browse files
committed
Revert "Changed PooledDb Pattern"
This reverts commit 6a72c12.
1 parent 0004cc7 commit 82c7804

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

LinkDotNet.Blog.Web/RegistrationExtensions/SqlRegistrationExtensions.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)