From f2555563a80242816a79327d3bd9b96bb11b1ebf Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 5 Mar 2024 10:59:39 -0500 Subject: [PATCH] optimize to use ITransientService rather than introducing a new IServerService interface which needs to be scanned --- .../OqtaneServiceCollectionExtensions.cs | 26 ++++++------------- .../HtmlText/Services/HtmlTextService.cs | 2 +- Oqtane.Shared/Interfaces/IServerService.cs | 9 ------- 3 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 Oqtane.Shared/Interfaces/IServerService.cs diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index 58cb0a6b..02f9ef16 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -297,24 +297,6 @@ namespace Microsoft.Extensions.DependencyInjection } } - // dynamically register module server transient services (using conventions) - implementationTypes = assembly.GetInterfaces(); - foreach (var implementationType in implementationTypes) - { - if (implementationType.AssemblyQualifiedName != 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,"); - var serviceType = Type.GetType(serviceName); - if (serviceType != null) - { - services.AddTransient(serviceType, implementationType); - } - } - } - // dynamically register module transient services (ie. server DBContext, repository classes) implementationTypes = assembly.GetInterfaces(); foreach (var implementationType in implementationTypes) @@ -322,6 +304,14 @@ 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); } } diff --git a/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs b/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs index 9cbf4ed8..b3a15549 100644 --- a/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs +++ b/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs @@ -12,7 +12,7 @@ using Oqtane.Shared; namespace Oqtane.Modules.HtmlText.Services { [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] - public class ServerHtmlTextService : IHtmlTextService, IServerService + public class ServerHtmlTextService : IHtmlTextService, ITransientService { private readonly IHtmlTextRepository _htmlText; private readonly IUserPermissions _userPermissions; diff --git a/Oqtane.Shared/Interfaces/IServerService.cs b/Oqtane.Shared/Interfaces/IServerService.cs deleted file mode 100644 index d5d888fd..00000000 --- a/Oqtane.Shared/Interfaces/IServerService.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Oqtane.Modules -{ - /// - /// Empty interface used to decorate server module services for auto registration as scoped - /// - public interface IServerService - { - } -}