using System; using System.Collections.Generic; using System.IO; using System.Reflection; using Abp.Collections.Extensions; using Abp.Modules; using Abp.Reflection; namespace Abp.PlugIns { public class FolderPlugInSource : IPlugInSource { public string Folder { get; } public SearchOption SearchOption { get; set; } private readonly Lazy> _assemblies; public FolderPlugInSource(string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly) { Folder = folder; SearchOption = searchOption; _assemblies = new Lazy>(LoadAssemblies, true); } public List GetAssemblies() { return _assemblies.Value; } public List GetModules() { var modules = new List(); 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 LoadAssemblies() { return AssemblyHelper.GetAllAssembliesInFolder(Folder, SearchOption); } } }