示例#1
0
        public async Task <IActionResult> TestLoadPlugin()
        {
            var path = Path.Combine(pluginManagers.GetBasePluginsPath(), "Brochure.Authority", "plugin.config");
            var p    = await pluginLoader.LoadPlugin(path);

            if (!(p is Plugins plugin))
            {
                return new ContentResult()
                       {
                           Content = "bbb"
                       }
            }
            ;

            var startConfigs = reflectorUtil.GetObjectOfBase <IStarupConfigure>(plugin.Assembly);

            //         var context = new PluginMiddleContext(app.ServiceProvider, plugin.Key);
            //  plugin.Context.Services.Add(context);
            foreach (var item in startConfigs)
            {
                item.Configure(plugin.Key, applicationBuilder);
            }
            mvcBuilder.AddApplicationPart(plugin.Assembly);

            PluginActionDescriptorChangeProvider.Instance.HasChanged = true;
            PluginActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
            return(new ContentResult()
            {
                Content = "aaa"
            });
        }
示例#2
0
        /// <summary>
        /// 加载插件
        /// </summary>
        private async Task ResolverPlugins()
        {
            var pluginBathPath = _pluginManagers.GetBasePluginsPath();
            var allPluginPath  = directory.GetFiles(pluginBathPath, "plugin.config", SearchOption.AllDirectories).ToList();
            var listPlugins    = new List <IPlugins>();

            //加载程序集
            foreach (var pluginConfigPath in allPluginPath)
            {
                try
                {
                    var p = await LoadPlugin(pluginConfigPath);

                    p.ConfigureService(p.Context.Services);
                    if (p != null)
                    {
                        listPlugins.Add(p);
                    }
                }
                catch (Exception e)
                {
                    log.LogError(e, e.Message);
                }
            }
            //执行插件初始化
            foreach (var plugin in listPlugins)
            {
                try
                {
                    _moduleLoader.LoadModule(plugin.Context.Services, plugin.Assembly);
                    if (await StartPlugin(plugin))
                    {
                        _pluginManagers.Regist(plugin);
                        NotifyLoad(plugin.Key);
                    }
                }
                catch (Exception e)
                {
                    log.LogError(e, e.Message);
                    if (plugin.Key != Guid.Empty)
                    {
                        await UnLoad(plugin.Key);
                    }
                }
            }
        }