Skip to content

Commit f15e8bf

Browse files
committed
Use pooled db context factory
1 parent e4ab2a2 commit f15e8bf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/LinkDotNet.Blog.Web/RegistrationExtensions/SqlRegistrationExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
1212
{
1313
services.AssertNotAlreadyRegistered(typeof(IRepository<>));
1414

15-
services.AddDbContextFactory<BlogDbContext>(
15+
services.AddPooledDbContextFactory<BlogDbContext>(
1616
(s, builder) =>
1717
{
1818
var configuration = s.GetRequiredService<AppConfiguration>();
1919
var connectionString = configuration.ConnectionString;
2020
builder.UseSqlServer(connectionString);
21-
},
22-
ServiceLifetime.Transient);
21+
});
2322

2423
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
2524
}
@@ -28,14 +27,13 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
2827
{
2928
services.AssertNotAlreadyRegistered(typeof(IRepository<>));
3029

31-
services.AddDbContextFactory<BlogDbContext>(
30+
services.AddPooledDbContextFactory<BlogDbContext>(
3231
(s, builder) =>
3332
{
3433
var configuration = s.GetRequiredService<AppConfiguration>();
3534
var connectionString = configuration.ConnectionString;
3635
builder.UseSqlite(connectionString);
37-
},
38-
ServiceLifetime.Transient);
36+
});
3937
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
4038
}
4139
}

0 commit comments

Comments
 (0)