2022-03-19 23:06:06 +04:00
|
|
|
|
using System;
|
2021-03-28 19:15:55 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml.XPath;
|
2022-03-20 10:10:44 +04:00
|
|
|
|
using ToolsModule.ManagmentExtension;
|
2021-03-28 19:15:55 +04:00
|
|
|
|
|
2022-03-20 10:10:44 +04:00
|
|
|
|
namespace ToolsModule.ManagmentDependency
|
2021-03-28 19:15:55 +04:00
|
|
|
|
{
|
2022-03-19 23:06:06 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Загрузчик данных
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static partial class ServiceProviderLoader
|
2021-03-28 19:15:55 +04:00
|
|
|
|
{
|
|
|
|
|
private static readonly string _pathToImplementationExt = "..\\..\\..\\..\\ImplementationExtensions\\";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Загрузка всех классов-реализаций IImplementationExtension
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2022-03-19 22:54:25 +04:00
|
|
|
|
public static List<IDependencyRegistration> GetImplementationExtensions()
|
2021-03-28 19:15:55 +04:00
|
|
|
|
{
|
2022-03-19 22:54:25 +04:00
|
|
|
|
var list = new List<IDependencyRegistration>();
|
2021-03-28 19:15:55 +04:00
|
|
|
|
if(Directory.Exists(_pathToImplementationExt))
|
|
|
|
|
{
|
|
|
|
|
var files = Directory.GetFiles(_pathToImplementationExt, "*.dll", SearchOption.AllDirectories);
|
|
|
|
|
var loadedFiles = new List<string>();
|
|
|
|
|
foreach(var file in files.Distinct())
|
|
|
|
|
{
|
|
|
|
|
if(loadedFiles.Contains(file.GetFileName()))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-03-19 22:54:25 +04:00
|
|
|
|
var asm = Assembly.LoadFrom(file);
|
2021-03-28 19:15:55 +04:00
|
|
|
|
foreach (var t in asm.GetExportedTypes())
|
|
|
|
|
{
|
2022-03-19 22:54:25 +04:00
|
|
|
|
if (t.IsClass && typeof(IDependencyRegistration).IsAssignableFrom(t))
|
2021-03-28 19:15:55 +04:00
|
|
|
|
{
|
2022-03-19 22:54:25 +04:00
|
|
|
|
list.Add((IDependencyRegistration)Activator.CreateInstance(t));
|
2021-03-28 19:15:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loadedFiles.Add(file.GetFileName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение имени файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static string GetFile(string fileName) => Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|