optimize to use ITransientService rather than introducing a new IServerService interface which needs to be scanned
This commit is contained in:
parent
b948961d52
commit
f2555563a8
|
@ -297,24 +297,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
}
|
||||
}
|
||||
|
||||
// dynamically register module server transient services (using conventions)
|
||||
implementationTypes = assembly.GetInterfaces<IServerService>();
|
||||
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<ITransientService>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
namespace Oqtane.Modules
|
||||
{
|
||||
/// <summary>
|
||||
/// Empty interface used to decorate server module services for auto registration as scoped
|
||||
/// </summary>
|
||||
public interface IServerService
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user