src/EasyFrameWork/Mvc/Plugin/AssemblyLoader.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Microsoft.Extensions.DependencyModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading.Tasks;
using Easy.Extend;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
namespace Easy.Mvc.Plugin
{
public class AssemblyLoader
{
private static Dictionary<string, Assembly> LoadedAssemblies { get; set; }
public AssemblyLoader(List<PluginInfo> plugins)
{
DependencyAssemblies = new List<Assembly>();
PluginInfos = plugins ?? new List<PluginInfo>();
}
public string CurrentPath { get; set; }
public string AssemblyPath { get; set; }
public Assembly CurrentAssembly { get; private set; }
public List<PluginInfo> PluginInfos { get; set; }
public List<Assembly> DependencyAssemblies { get; private set; }
private readonly TypeInfo PluginTypeInfo = typeof(IPluginStartup).GetTypeInfo();
public IEnumerable<Assembly> LoadPlugin(string path)
{
if (CurrentAssembly == null)
{
AssemblyPath = path;
CurrentAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
ResolveDenpendency(CurrentAssembly);
yield return CurrentAssembly;
foreach (var item in DependencyAssemblies)
{
yield return item;
}
}
else { throw new Exception("A loader just can load one assembly."); }
}
private void ResolveDenpendency(Assembly assembly)
{
if (LoadedAssemblies == null)
{
LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary(m => GetAssemblyNameVersion(m.GetName()));
}
string nameVersion = GetAssemblyNameVersion(assembly.GetName());
if (!LoadedAssemblies.ContainsKey(nameVersion))
{
LoadedAssemblies.Add(nameVersion, assembly);
后面还有 45 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。