src/EasyFrameWork/Mvc/Plugin/PluginActivtor.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Easy.Mvc.Plugin
{
    public static class PluginActivtor
    {
        public static List<PluginDescriptor> LoadedPlugins { get; set; } = new List<PluginDescriptor>();
        public static IServiceCollection ConfigurePlugin(this IServiceCollection serviceCollection)
        {
            var pluginType = typeof(IPluginStartup);
            foreach (var item in LoadedPlugins)
            {
                serviceCollection.AddTransient(pluginType, item.PluginType);
                serviceCollection.AddTransient(item.PluginType);
            }
            return serviceCollection;
        }
        public static IApplicationBuilder ConfigurePlugin(this IApplicationBuilder applicationBuilder, IWebHostEnvironment hostingEnvironment)
        {
            foreach (var item in applicationBuilder.ApplicationServices.GetPlugins())
            {
                item.ConfigureApplication(applicationBuilder, hostingEnvironment);
            }
            return applicationBuilder;
        }
        public static IEnumerable<IPluginStartup> GetPlugins(this IServiceProvider serviceProvider)
        {
            foreach (var item in LoadedPlugins)
            {
                var plugin = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, item.PluginType) as IPluginStartup;
                plugin.Assembly = item.Assembly;
                plugin.Dependencies = item.Dependencies;
                plugin.CurrentPluginPath = item.CurrentPluginPath;
                yield return plugin;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。