using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Abp.Collections.Extensions; using Abp.Modules; namespace Abp.PlugIns { //TODO: This class is similar to FolderPlugInSource. Create an abstract base class for them. public class AssemblyFileListPlugInSource : IPlugInSource { public string[] FilePaths { get; } private readonly Lazy> _assemblies; public AssemblyFileListPlugInSource(params string[] filePaths) { FilePaths = filePaths ?? new string[0]; _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 FilePaths.Select( Assembly.LoadFile //TODO: Use AssemblyLoadContext.Default.LoadFromAssemblyPath instead? ).ToList(); } } }