0
0

Don't use PooledDbContextFactory when initially loading config

This commit is contained in:
Rhys Ickeringill
2025-12-28 16:19:33 +11:00
parent d80dd87d66
commit b7848d71d6
6 changed files with 23 additions and 11 deletions

View File

@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
namespace RAIC.Extensions.Configuration.EntityFrameworkCore.Extensions;
@@ -21,13 +20,13 @@ public static class ConfigurationBuilderExtensions
/// </param>
/// <returns>The <see cref="IConfigurationBuilder"/></returns>
public static IConfigurationBuilder AddDbSet<TDbContext, TSetting>(this IConfigurationBuilder builder, DbContextOptionsTransformer<TDbContext> optionsTransformer)
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>, ISettingsDbContextFactory<TDbContext>
where TSetting : class, ISetting
{
// DEBT: Find way to create non-pooled DbContextFactory since this is only a short lived usage
var options = optionsTransformer(new DbContextOptionsBuilder<TDbContext>()).Options;
var configurationSource = new EntityFrameworkCoreDbSetConfigurationSource<TDbContext, TSetting>()
{
DbContextFactory = new PooledDbContextFactory<TDbContext>(optionsTransformer(new DbContextOptionsBuilder<TDbContext>()).Options, poolSize: 1)
DbContextFactory = () => TDbContext.Create(options)
};
return builder.Add(configurationSource);