|
|
@ -2,7 +2,6 @@
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Runtime.Loader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ds.WMS.WebCore
|
|
|
|
namespace Ds.WMS.WebCore
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -13,10 +12,34 @@ namespace Ds.WMS.WebCore
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static WebApplicationBuilder UseDynamicStartups(this WebApplicationBuilder builder)
|
|
|
|
public static WebApplicationBuilder UseDynamicStartups(this WebApplicationBuilder builder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// 此方案可能查找不到程序集 顾使用手动加载方式
|
|
|
|
|
|
|
|
// var dynamicStartups = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
|
|
|
|
|
//.SelectMany(a => a.GetTypes())
|
|
|
|
|
|
|
|
//.Select(t =>
|
|
|
|
|
|
|
|
//new
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// Type = t,
|
|
|
|
|
|
|
|
// Attribute = t.GetCustomAttribute<DsStartupAttribute>()
|
|
|
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
//.Where(x => x.Attribute != null)
|
|
|
|
|
|
|
|
// .OrderBy(x => x.Attribute.Order)
|
|
|
|
|
|
|
|
//.Select(x => Activator.CreateInstance(x.Type))
|
|
|
|
|
|
|
|
//.OfType<IDynamicStartup>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var assemblyNames = new List<string>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Ds.WMS.Finance.MediatR",
|
|
|
|
|
|
|
|
"DS.Module.SqlSugar"
|
|
|
|
|
|
|
|
// 其他程序集的名称...
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dynamicStartups = new List<IDynamicStartup>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var assemblyName in assemblyNames)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var assembly = Assembly.Load(assemblyName);
|
|
|
|
|
|
|
|
|
|
|
|
var dynamicStartups = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
|
var startups = assembly.GetTypes()
|
|
|
|
.SelectMany(a => a.GetTypes())
|
|
|
|
|
|
|
|
.Select(t =>
|
|
|
|
.Select(t =>
|
|
|
|
new
|
|
|
|
new
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -26,28 +49,11 @@ namespace Ds.WMS.WebCore
|
|
|
|
.Where(x => x.Attribute != null)
|
|
|
|
.Where(x => x.Attribute != null)
|
|
|
|
.OrderBy(x => x.Attribute.Order)
|
|
|
|
.OrderBy(x => x.Attribute.Order)
|
|
|
|
.Select(x => Activator.CreateInstance(x.Type))
|
|
|
|
.Select(x => Activator.CreateInstance(x.Type))
|
|
|
|
.OfType<IDynamicStartup>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = AssemblyLoadContext.Default.Assemblies.SelectMany(a => a.GetTypes())
|
|
|
|
|
|
|
|
.Select(t => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type = t,
|
|
|
|
|
|
|
|
Attribute = t.GetCustomAttribute<DsStartupAttribute>()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// .Where(x => x.Attribute != null)
|
|
|
|
|
|
|
|
.OfType<IDynamicStartup>()
|
|
|
|
.OfType<IDynamicStartup>()
|
|
|
|
.ToList();
|
|
|
|
.ToList();
|
|
|
|
// var dynamicStartups = AssemblyLoadContext.Default.Assemblies
|
|
|
|
|
|
|
|
//.SelectMany(a => a.GetTypes())
|
|
|
|
dynamicStartups.AddRange(startups);
|
|
|
|
//.Select(t => new
|
|
|
|
}
|
|
|
|
//{
|
|
|
|
|
|
|
|
// Type = t,
|
|
|
|
|
|
|
|
// Attribute = t.GetCustomAttribute<DsStartupAttribute>()
|
|
|
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
//.Where(x => x.Attribute != null)
|
|
|
|
|
|
|
|
//.OrderBy(x => x.Attribute.Order)
|
|
|
|
|
|
|
|
//.Select(x => Activator.CreateInstance(x.Type))
|
|
|
|
|
|
|
|
//.OfType<IDynamicStartup>();
|
|
|
|
|
|
|
|
foreach (var startup in dynamicStartups)
|
|
|
|
foreach (var startup in dynamicStartups)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
startup.ConfigureServices(builder);
|
|
|
|
startup.ConfigureServices(builder);
|
|
|
@ -73,8 +79,4 @@ namespace Ds.WMS.WebCore
|
|
|
|
return app;
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|