src/EasyFrameWork/Mvc/Plugin/Loader.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy.Extend;
using Easy.Serializer;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Easy.Mvc.Plugin
{
public class Loader : IPluginLoader
{
public const string PluginFolder = "Plugins";
private const string PluginInfoFile = "zkea.plugin";
#if DEBUG
private readonly string[] AltDevelopmentPath = new[] { "bin", "Debug", "net6.0" };
#else
private readonly string[] AltDevelopmentPath = new[] { "bin", "Release", "net6.0" };
#endif
private readonly static List<AssemblyLoader> Loaders = new List<AssemblyLoader>();
private readonly static Dictionary<string, Assembly> LoadedAssemblies = new Dictionary<string, Assembly>();
public Loader(IWebHostEnvironment hostEnvironment)
{
HostingEnvironment = hostEnvironment;
}
public IWebHostEnvironment HostingEnvironment { get; set; }
public IEnumerable<IPluginStartup> LoadEnablePlugins(IServiceCollection serviceCollection)
{
var start = DateTime.Now;
List<PluginInfo> availablePlugins = GetPlugins().Where(m => m.Enable && m.ID.IsNotNullAndWhiteSpace()).ToList();
Loaders.AddRange(availablePlugins.Select(m =>
{
var loader = new AssemblyLoader(availablePlugins)
{
CurrentPath = m.RelativePath
};
var assemblyPath = Path.Combine(m.RelativePath, (HostingEnvironment.IsDevelopment() ? Path.Combine(AltDevelopmentPath) : string.Empty), m.FileName);
Console.WriteLine("Loading: {0}", m.Name);
var assemblies = loader.LoadPlugin(assemblyPath);
assemblies.Each(assembly =>
{
if (!LoadedAssemblies.ContainsKey(assembly.FullName))
{
LoadedAssemblies.Add(assembly.FullName, assembly);
}
});
return loader;
}));
Console.WriteLine("All plugins are loaded. Elapsed: {0}ms", (DateTime.Now - start).Milliseconds);
return serviceCollection.ConfigurePlugin().BuildServiceProvider().GetPlugins();
}
后面还有 53 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。