From 4f0567c2e02d1bbdfe497dad9b948d3ecf4d3c3a Mon Sep 17 00:00:00 2001 From: liaoxujun@qq.com <liaoxujun@qq.com> Date: 星期三, 26 七月 2023 16:03:13 +0800 Subject: [PATCH] 增加配置文件,增加数据库codefirst --- DocumentServiceAPI.Utility/UtilityFun.cs | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-) diff --git a/DocumentServiceAPI.Utility/UtilityFun.cs b/DocumentServiceAPI.Utility/UtilityFun.cs new file mode 100644 index 0000000..7ca5140 --- /dev/null +++ b/DocumentServiceAPI.Utility/UtilityFun.cs @@ -0,0 +1,84 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.Loader; +using System.Text; +using System.Threading.Tasks; + +namespace DocumentServiceAPI.Utility +{ + public class UtilityFun + { + + /// <summary> + /// 鑾峰彇鎵�鏈夌▼搴忕洰褰曚笅鍜屽父鐢ㄧ殑绋嬪簭闆� 鍖呮嫭涓�浜涚郴缁熷紩鐢ㄧ▼搴忛泦 + /// </summary> + /// <returns> 褰撳墠宸ョ▼涓嬬殑绋嬪簭闆�</returns> + private static List<Assembly>? _allAssemblies = null; + + public static List<Assembly> GetAllAssembly() + { + + + if (_allAssemblies == null) + { + _allAssemblies = new List<Assembly>(); + string path = null; + string singlefile = null; + try + { + path = Assembly.GetEntryAssembly()?.Location; + } + catch { } + if (string.IsNullOrEmpty(path)) + { + singlefile = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; + path = Path.GetDirectoryName(singlefile); + } + var dir = new DirectoryInfo(Path.GetDirectoryName(path)); + + var dlls = dir.GetFiles("*.dll", SearchOption.TopDirectoryOnly); + string[] systemdll = new string[] + { + "Microsoft.", + "System.", + "Swashbuckle.", + "ICSharpCode", + "Newtonsoft.", + "Oracle.", + "Pomelo.", + "SQLitePCLRaw.", + "Aliyun.OSS", + "BouncyCastle.", + "FreeSql.", + "Google.Protobuf.dll", + "Humanizer.dll", + "IdleBus.dll", + "K4os.", + "MySql.Data.", + "Npgsql.", + "NPOI.", + "netstandard", + "MySqlConnector", + "VueCliMiddleware" + }; + + var filtered = dlls.Where(x => systemdll.Any(y => x.Name.StartsWith(y)) == false); + foreach (var dll in filtered) + { + try + { + AssemblyLoadContext.Default.LoadFromAssemblyPath(dll.FullName); + } + catch + { + } + } + var dlllist = AssemblyLoadContext.Default.Assemblies.Where(x => systemdll.Any(y => x.FullName.StartsWith(y)) == false).ToList(); + _allAssemblies.AddRange(dlllist); + } + return _allAssemblies; + } + } +} -- Gitblit v1.9.1