Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use IServerStartup rather than class naming convention to register server service class #3971

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static IServiceCollection AddOqtaneServices(this IServiceCollection serv
{
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);
}
}
Expand All @@ -303,14 +303,6 @@ private static IServiceCollection AddOqtaneServices(this IServiceCollection serv
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
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)
{
Expand All @@ -19,6 +21,7 @@ public void ConfigureMvc(IMvcBuilder mvcBuilder)

public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IHtmlTextService, ServerHtmlTextService>();
services.AddDbContextFactory<HtmlTextContext>(opt => { }, ServiceLifetime.Transient);
}
}
Expand Down