From 074fcaaa73436dba54bd1ad26f4d0599be4cc130 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 8 Mar 2024 07:39:34 -0500 Subject: [PATCH] use IServerStartup for registering DbContextFactory --- .../OqtaneServiceCollectionExtensions.cs | 13 ---------- .../Repository/HtmlTextDbContextFactory.cs | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 Oqtane.Server/Modules/HtmlText/Repository/HtmlTextDbContextFactory.cs diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index 84e45bca..f3a04ed8 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -312,19 +312,6 @@ namespace Microsoft.Extensions.DependencyInjection serviceType = Type.GetType(serviceName); } services.AddTransient(serviceType ?? implementationType, implementationType); - - if (implementationType.BaseType == typeof(DBContextBase)) - { - if (implementationType.Name == "HtmlTextContext") - { - services.AddDbContextFactory(opt => { }, ServiceLifetime.Transient); - } - // need a way to call AddDbContextFactory dynamically passing the implementationType - //typeof(IServiceCollection) - // .GetMethod("AddDbContextFactory") - // .MakeGenericMethod(implementationType) - // .Invoke(services, new object[] { new DbContextOptionsBuilder(), ServiceLifetime.Scoped }); - } } } diff --git a/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextDbContextFactory.cs b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextDbContextFactory.cs new file mode 100644 index 00000000..88eebf06 --- /dev/null +++ b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextDbContextFactory.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Oqtane.Infrastructure; + +namespace Oqtane.Modules.HtmlText.Repository +{ + public class HtmlTextDbContextFactory : IServerStartup + { + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + // not implemented + } + + public void ConfigureMvc(IMvcBuilder mvcBuilder) + { + // not implemented + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddDbContextFactory(opt => { }, ServiceLifetime.Transient); + } + } +}