|
|
|
@ -2,7 +2,6 @@
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.Loader;
|
|
|
|
|
|
|
|
|
|
namespace Ds.WMS.WebCore
|
|
|
|
|
{
|
|
|
|
@ -13,41 +12,48 @@ namespace Ds.WMS.WebCore
|
|
|
|
|
{
|
|
|
|
|
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 list = AssemblyLoadContext.Default.Assemblies.SelectMany(a => a.GetTypes())
|
|
|
|
|
.Select(t => new
|
|
|
|
|
{
|
|
|
|
|
Type = t,
|
|
|
|
|
Attribute = t.GetCustomAttribute<DsStartupAttribute>()
|
|
|
|
|
})
|
|
|
|
|
// .Where(x => x.Attribute != null)
|
|
|
|
|
.OfType<IDynamicStartup>()
|
|
|
|
|
.ToList();
|
|
|
|
|
// var dynamicStartups = AssemblyLoadContext.Default.Assemblies
|
|
|
|
|
// 此方案可能查找不到程序集 顾使用手动加载方式
|
|
|
|
|
// var dynamicStartups = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
|
|
//.SelectMany(a => a.GetTypes())
|
|
|
|
|
//.Select(t => new
|
|
|
|
|
//.Select(t =>
|
|
|
|
|
//new
|
|
|
|
|
//{
|
|
|
|
|
// Type = t,
|
|
|
|
|
// Attribute = t.GetCustomAttribute<DsStartupAttribute>()
|
|
|
|
|
//})
|
|
|
|
|
//.Where(x => x.Attribute != null)
|
|
|
|
|
//.OrderBy(x => x.Attribute.Order)
|
|
|
|
|
// .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 startups = assembly.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>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
dynamicStartups.AddRange(startups);
|
|
|
|
|
}
|
|
|
|
|
foreach (var startup in dynamicStartups)
|
|
|
|
|
{
|
|
|
|
|
startup.ConfigureServices(builder);
|
|
|
|
@ -73,8 +79,4 @@ namespace Ds.WMS.WebCore
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|