【问题标题】:ASP.NET Boilerplate Plugin Module or Dynamic ModuleASP.NET 样板插件模块或动态模块
【发布时间】:2018-04-04 09:20:50
【问题描述】:

我是一名 .NET 开发人员,目前我正在尝试学习 ASP.NET Boilerplate。我遇到了PlugIn Modules,我知道它可以用于模块依赖,但他们有这些我想理解的行:

AbpBootstrapper 类定义了 PlugInSources 属性,可用于添加源以动态加载插件模块。插件源可以是任何实现 IPlugInSource 接口的类。 PlugInFolderSource 类实现它以从位于文件夹中的程序集中获取插件模块。

所以在尝试实现IPlugInSource接口之后:

using Abp.Modules;
using Abp.PlugIns;
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

public class EmpDetails : IPlugInSource
{
    public string EmpName { get; set; }
    public string Address { get; set; }
    public string Email { get; set; }

    public List<Assembly> GetAssemblies()
    {
        throw new NotImplementedException();
    }

    public List<Type> GetModules()
    {
        throw new NotImplementedException();
    }
}

我的疑问是:我必须在GetAssemblies()GetModules() 方法中执行什么操作,如我必须返回哪个AssembliesType?我参考了官方网站文档,如果他们提供了正确的示例,我无法在其中找到。提前致谢。

【问题讨论】:

    标签: c# asp.net plugins module aspnetboilerplate


    【解决方案1】:

    您不应实施IPlugInSource

    文档提供了一个清晰的示例,说明如何Startup 类中添加插件源

    services.AddAbp<MyStartupModule>(options =>
    {
        options.PlugInSources.AddFolder(@"C:\MyPlugIns");
    });
    

    要清除您的疑问,请参阅 FolderPlugInSource 中的 GetAssembliesGetModules 方法:

    public class FolderPlugInSource : IPlugInSource
    {
        public string Folder { get; }
    
        public SearchOption SearchOption { get; set; }
    
        private readonly Lazy<List<Assembly>> _assemblies;
    
        public FolderPlugInSource(string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            Folder = folder;
            SearchOption = searchOption;
    
            _assemblies = new Lazy<List<Assembly>>(LoadAssemblies, true);
        }
    
        public List<Assembly> GetAssemblies()
        {
            return _assemblies.Value;
        }
    
        public List<Type> GetModules()
        {
            var modules = new List<Type>();
    
            foreach (var assembly in GetAssemblies())
            {
                try
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        if (AbpModule.IsAbpModule(type))
                        {
                            modules.AddIfNotContains(type);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new AbpInitializationException("Could not get module types from assembly: " + assembly.FullName, ex);
                }
            }
    
            return modules;
        }
    
        private List<Assembly> LoadAssemblies()
        {
            return AssemblyHelper.GetAllAssembliesInFolder(Folder, SearchOption);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 2023-01-13
      • 2023-04-03
      • 2014-09-21
      相关资源
      最近更新 更多