Server naming fixes and cleanup
Server is now completely cleaned up and without warnings
This commit is contained in:
@ -8,15 +8,16 @@ using Microsoft.Extensions.Hosting;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Modules;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class OqtaneServiceCollectionExtensions
|
||||
{
|
||||
private static readonly IList<Assembly> _oqtaneModuleAssemblies = new List<Assembly>();
|
||||
private static readonly IList<Assembly> OqtaneModuleAssemblies = new List<Assembly>();
|
||||
|
||||
private static Assembly[] Assemblies => AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
internal static IEnumerable<Assembly> GetOqtaneModuleAssemblies() => _oqtaneModuleAssemblies;
|
||||
internal static IEnumerable<Assembly> GetOqtaneModuleAssemblies() => OqtaneModuleAssemblies;
|
||||
|
||||
public static IServiceCollection AddOqtaneModules(this IServiceCollection services)
|
||||
{
|
||||
@ -50,15 +51,17 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
}
|
||||
|
||||
// dynamically register module services, contexts, and repository classes
|
||||
var assemblies = Assemblies.
|
||||
Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
|
||||
var assemblies = Assemblies.Where(item => item.FullName != null && (item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module."))).ToArray();
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
var implementationTypes = assembly.GetInterfaces<IService>();
|
||||
foreach (var implementationType in implementationTypes)
|
||||
{
|
||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
||||
services.AddScoped(serviceType ?? implementationType, implementationType);
|
||||
if (implementationType.AssemblyQualifiedName != null)
|
||||
{
|
||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
||||
services.AddScoped(serviceType ?? implementationType, implementationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,14 +94,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
|
||||
private static void LoadAssemblies(string pattern)
|
||||
{
|
||||
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
if (assemblyPath == null) return;
|
||||
|
||||
var assembliesFolder = new DirectoryInfo(assemblyPath);
|
||||
|
||||
// iterate through Oqtane theme assemblies in /bin ( filter is narrow to optimize loading process )
|
||||
foreach (var file in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll"))
|
||||
{
|
||||
// check if assembly is already loaded
|
||||
var assembly = Assemblies.Where(a => a.Location == file.FullName).FirstOrDefault();
|
||||
var assembly = Assemblies.FirstOrDefault(a => a.Location == file.FullName);
|
||||
if (assembly == null)
|
||||
{
|
||||
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
|
||||
@ -106,7 +111,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
if (pattern == "Module")
|
||||
{
|
||||
// build a list of module assemblies
|
||||
_oqtaneModuleAssemblies.Add(assembly);
|
||||
OqtaneModuleAssemblies.Add(assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user