| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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<List<Assembly>> _assemblies;
- public AssemblyFileListPlugInSource(params string[] filePaths)
- {
- FilePaths = filePaths ?? new string[0];
- _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 FilePaths.Select(
- Assembly.LoadFile //TODO: Use AssemblyLoadContext.Default.LoadFromAssemblyPath instead?
- ).ToList();
- }
- }
- }
|