插件开发测试完成
This commit is contained in:
parent
488a717875
commit
850f3efabd
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
|
@ -22,6 +23,7 @@ namespace Falcon.SugarApi.Plugin
|
|||
/// </summary>
|
||||
/// <param name="assemblyPath">程序集路径</param>
|
||||
/// <returns>程序集</returns>
|
||||
[Obsolete("方法存在问题,程序集注册的对象无法实现注入,目前未解决。使用AssemblyLoad代替",false)]
|
||||
public static Assembly ALCLoad(string assemblyPath) {
|
||||
var context = new AssemblyLoadContext(assemblyPath);
|
||||
return context.LoadFromAssemblyPath(assemblyPath);
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Falcon.SugarApi.Plugin.Client
|
|||
return;
|
||||
}
|
||||
apm.ApplicationParts.Add(part);
|
||||
|
||||
});
|
||||
return services;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,11 @@ namespace Falcon.SugarApi.Plugin.Service
|
|||
/// </summary>
|
||||
public static class IServiceCollectionExtend
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
//public static List<Assembly> Plugins { get; set; } = new List<Assembly>();
|
||||
|
||||
/// <summary>
|
||||
/// 注册插件。
|
||||
/// <para>查找插件中的IServicePlugin实现,并运行其中的AddServices方法注册和初始化插件</para>
|
||||
|
@ -26,7 +31,6 @@ namespace Falcon.SugarApi.Plugin.Service
|
|||
if(name == null) {
|
||||
return services;
|
||||
}
|
||||
List<Assembly> plugin = new();
|
||||
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
foreach(var pn in pluginNames) {
|
||||
var pf = pn.EndsWith(".dll") ? pn : pn + ".dll";
|
||||
|
@ -42,12 +46,13 @@ namespace Falcon.SugarApi.Plugin.Service
|
|||
if(!File.Exists(pf)) {
|
||||
throw new FileNotFoundException(pf);
|
||||
}
|
||||
var pa = AssemblyLoadHelp.ALCLoad(pf);
|
||||
//var pa = AssemblyLoadHelp.ALCLoad(pf);
|
||||
var pa = AssemblyLoadHelp.AssemblyLoad(pf);
|
||||
|
||||
if(pa != null) {
|
||||
plugin.Add(pa);
|
||||
services.AddPluginService(config,pa);
|
||||
}
|
||||
}
|
||||
services.AddPluginService(config,plugin.ToArray());
|
||||
return services;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user