完善插件组件
This commit is contained in:
		
							parent
							
								
									5f9dbb238a
								
							
						
					
					
						commit
						251373c6bf
					
				
							
								
								
									
										26
									
								
								Falcon.SugarApi/Plugin/PluginOptions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Falcon.SugarApi/Plugin/PluginOptions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
namespace Falcon.SugarApi.Plugin
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 插件配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class PluginOptions
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 插件安装搜索目录
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static List<string> PluginPaths { get; private set; } = new List<string>() { "","/plugin" };
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 插件配置文件中Swagger定义节点名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string SwiggerDefincePathName { get; private set; } = "swagger";
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 插件配置文件名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static List<string> PluginNames { get; private set; } = new List<string>();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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<Assembly> 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);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user