IClientStartup implementation
This commit is contained in:
@ -170,6 +170,16 @@ namespace Oqtane.Controllers
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// GET api/<controller>/load/assembyname
|
||||
[HttpGet("load")]
|
||||
public List<string> Load()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneClientAssemblies();
|
||||
var list = AppDomain.CurrentDomain.GetOqtaneClientAssemblies().Select(a => a.GetName().Name).ToList();
|
||||
var deps = assemblies.SelectMany(a => a.GetReferencedAssemblies()).Distinct();
|
||||
list.AddRange(deps.Where(a=>a.Name.EndsWith(".oqtane",StringComparison.OrdinalIgnoreCase)).Select(a=>a.Name));
|
||||
return list;
|
||||
}
|
||||
|
||||
// POST api/<controller>?moduleid=x
|
||||
[HttpPost]
|
||||
|
@ -1,69 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace System.Reflection
|
||||
{
|
||||
public static class AssemblyExtensions
|
||||
{
|
||||
public static IEnumerable<Type> GetInterfaces<TInterfaceType>(this Assembly assembly)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
return assembly.GetTypes(typeof(TInterfaceType));
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypes(this Assembly assembly, Type interfaceType)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
if (interfaceType is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(interfaceType));
|
||||
}
|
||||
|
||||
return assembly.GetTypes()
|
||||
//.Where(t => t.GetInterfaces().Contains(interfaceType));
|
||||
.Where(x => interfaceType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetInstances<T>(this Assembly assembly) where T : class
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
var type = typeof(T);
|
||||
var list = assembly.GetTypes()
|
||||
.Where(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract && !x.IsGenericType);
|
||||
|
||||
foreach (var type1 in list)
|
||||
{
|
||||
if (Activator.CreateInstance(type1) is T instance) yield return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsOqtaneAssembly(this Assembly assembly)
|
||||
{
|
||||
return assembly.FullName != null && (assembly.FullName.Contains("oqtane", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public static bool IsOqtaneAssembly(this FileInfo fileInfo)
|
||||
{
|
||||
return (fileInfo.Name.Contains("oqtane", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public static IEnumerable<Assembly> GetOqtaneAssemblies(this AppDomain appDomain)
|
||||
{
|
||||
return appDomain.GetAssemblies().Where(a => a.IsOqtaneAssembly());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,21 +8,23 @@ using Microsoft.Extensions.Hosting;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.UI;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class OqtaneServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddOqtaneParts(this IServiceCollection services)
|
||||
public static IServiceCollection AddOqtaneParts(this IServiceCollection services, Runtime runtime)
|
||||
{
|
||||
LoadAssemblies();
|
||||
services.AddOqtaneServices();
|
||||
services.AddOqtaneServices(runtime);
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection AddOqtaneServices(this IServiceCollection services)
|
||||
private static IServiceCollection AddOqtaneServices(this IServiceCollection services, Runtime runtime)
|
||||
{
|
||||
if (services is null)
|
||||
{
|
||||
@ -59,6 +61,13 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
startup.ConfigureServices(services);
|
||||
}
|
||||
|
||||
if (runtime == Runtime.Server)
|
||||
{
|
||||
assembly.GetInstances<IClientStartup>()
|
||||
.ToList()
|
||||
.ForEach(x => x.ConfigureServices(services));
|
||||
}
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.UI;
|
||||
|
||||
namespace Oqtane
|
||||
{
|
||||
@ -27,6 +28,7 @@ namespace Oqtane
|
||||
{
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
private string _webRoot;
|
||||
private Runtime _runtime;
|
||||
|
||||
public Startup(IWebHostEnvironment env)
|
||||
{
|
||||
@ -34,6 +36,9 @@ namespace Oqtane
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
Configuration = builder.Build();
|
||||
|
||||
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
||||
|
||||
_webRoot = env.WebRootPath;
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(env.ContentRootPath, "Data"));
|
||||
}
|
||||
@ -189,7 +194,7 @@ namespace Oqtane
|
||||
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
||||
|
||||
// load the external assemblies into the app domain, install services
|
||||
services.AddOqtaneParts();
|
||||
services.AddOqtaneParts(_runtime);
|
||||
|
||||
services.AddMvc()
|
||||
.AddNewtonsoftJson()
|
||||
|
Reference in New Issue
Block a user