diff --git a/Falcon.SugarApi/Plugin/PluginOptions.cs b/Falcon.SugarApi/Plugin/PluginOptions.cs new file mode 100644 index 0000000..185bcae --- /dev/null +++ b/Falcon.SugarApi/Plugin/PluginOptions.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace Falcon.SugarApi.Plugin +{ + /// + /// 插件配置 + /// + public static class PluginOptions + { + /// + /// 插件安装搜索目录 + /// + public static List PluginPaths { get; private set; } = new List() { "","/plugin" }; + + /// + /// 插件配置文件中Swagger定义节点名称 + /// + public static string SwiggerDefincePathName { get; private set; } = "swagger"; + + /// + /// 插件配置文件名称 + /// + public static List PluginNames { get; private set; } = new List(); + + } +} diff --git a/Falcon.SugarApi/Plugin/Service/IServiceCollectionExtend.cs b/Falcon.SugarApi/Plugin/Service/IServiceCollectionExtend.cs index 61250e5..c8a91c7 100644 --- a/Falcon.SugarApi/Plugin/Service/IServiceCollectionExtend.cs +++ b/Falcon.SugarApi/Plugin/Service/IServiceCollectionExtend.cs @@ -1,16 +1,10 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; using System; using System.Collections.Generic; -using System.Configuration; using System.IO; -using System.Linq; using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using System.Threading.Tasks; namespace Falcon.SugarApi.Plugin.Service { @@ -34,15 +28,16 @@ namespace Falcon.SugarApi.Plugin.Service } List plugin = new(); var basePath = AppDomain.CurrentDomain.BaseDirectory; - var pluginPath = @"plugin"; foreach(var pn in pluginNames) { - var pf = pn.EndsWith(".dll") ? pn : pn + ".dll"; - pf = Path.IsPathRooted(pf) ? pf : Path.Combine(basePath,pluginPath,pf); - - if(!File.Exists(pf)) { - pf = Path.IsPathRooted(pn) ? pf : Path.Combine(basePath,pn); - pf = pf.EndsWith(".dll") ? pf : pf + ".dll"; + if(!Path.IsPathRooted(pf)) { + foreach(var path in PluginOptions.PluginPaths) { + var tfp = Path.Combine(basePath,path,pf); + if(File.Exists(tfp)) { + pf = tfp; + break; + } + } } if(!File.Exists(pf)) { throw new FileNotFoundException(pf); @@ -86,7 +81,7 @@ namespace Falcon.SugarApi.Plugin.Service obj.AddServices(services,config); } catch(Exception ex) { - throw new Exception($"注册插件{type.FullName}.IServicePlugin.AddServices]方法时发生异常。",ex); + throw new Exception($"调用插件{type.FullName}.IServicePlugin.AddServices]方法时发生异常。",ex); } } }