use IServerStartup rather than class naming convention to register server service class
This commit is contained in:
parent
9106f9676c
commit
4457487e2a
@ -291,7 +291,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
if (implementationType.AssemblyQualifiedName != null)
|
||||
{
|
||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}")); var serviceName = implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}");
|
||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
||||
services.AddScoped(serviceType ?? implementationType, implementationType);
|
||||
}
|
||||
}
|
||||
@ -303,14 +303,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
if (implementationType.AssemblyQualifiedName != null)
|
||||
{
|
||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
||||
if (serviceType == null && implementationType.AssemblyQualifiedName.Contains("Services.Server"))
|
||||
{
|
||||
// module server services reference a common interface which is located in the client assembly
|
||||
var serviceName = implementationType.AssemblyQualifiedName
|
||||
// convert implementation type name to interface name and change Server assembly to Client
|
||||
.Replace(".Services.Server", ".Services.I").Replace(".Server,", ".Client,");
|
||||
serviceType = Type.GetType(serviceName);
|
||||
}
|
||||
services.AddTransient(serviceType ?? implementationType, implementationType);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using Oqtane.Modules.HtmlText.Services;
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Repository
|
||||
namespace Oqtane.Modules.HtmlText.Startup
|
||||
{
|
||||
public class HtmlTextDbContextFactory : IServerStartup
|
||||
public class ServerStartup : IServerStartup
|
||||
{
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
@ -19,6 +21,7 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IHtmlTextService, ServerHtmlTextService>();
|
||||
services.AddDbContextFactory<HtmlTextContext>(opt => { }, ServiceLifetime.Transient);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user