use DBContextFactory

This commit is contained in:
sbwalker
2024-03-06 11:36:56 -05:00
parent f6c45cd85a
commit 06bd964adc
3 changed files with 27 additions and 12 deletions

View File

@ -21,7 +21,6 @@ using Microsoft.OpenApi.Models;
using Oqtane.Infrastructure;
using Oqtane.Infrastructure.Interfaces;
using Oqtane.Managers;
using Oqtane.Models;
using Oqtane.Modules;
using Oqtane.Repository;
using Oqtane.Security;
@ -45,7 +44,6 @@ namespace Microsoft.Extensions.DependencyInjection
{
services.AddDbContext<MasterDBContext>(options => { }, ServiceLifetime.Transient);
services.AddDbContext<TenantDBContext>(options => { }, ServiceLifetime.Transient);
return services;
}
@ -313,6 +311,19 @@ namespace Microsoft.Extensions.DependencyInjection
serviceType = Type.GetType(serviceName);
}
services.AddTransient(serviceType ?? implementationType, implementationType);
if (implementationType.BaseType == typeof(DBContextBase))
{
if (implementationType.Name == "HtmlTextContext")
{
services.AddDbContextFactory<Oqtane.Modules.HtmlText.Repository.HtmlTextContext>(opt => { }, ServiceLifetime.Scoped);
}
// need a way to call AddDbContextFactory dynamically passing the implementationType
//typeof(IServiceCollection)
// .GetMethod("AddDbContextFactory")
// .MakeGenericMethod(implementationType)
// .Invoke(services, new object[] { new DbContextOptionsBuilder(), ServiceLifetime.Scoped });
}
}
}