зависимости какие то
This commit is contained in:
parent
9c7400183c
commit
632e6609a2
@ -65,23 +65,6 @@ namespace LawFirm
|
|||||||
option.AddNLog("nlog.config");
|
option.AddNLog("nlog.config");
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyManager.Instance.RegisterType<IBlankLogic, BlankLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IDocumentLogic, DocumentLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
|
||||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
|
||||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
|
||||||
|
|
||||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
|
||||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
|
||||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
|
||||||
|
|
||||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(isSingle: true);
|
|
||||||
|
|
||||||
DependencyManager.Instance.RegisterType<FormMain>();
|
DependencyManager.Instance.RegisterType<FormMain>();
|
||||||
DependencyManager.Instance.RegisterType<FormBlank>();
|
DependencyManager.Instance.RegisterType<FormBlank>();
|
||||||
DependencyManager.Instance.RegisterType<FormBlanks>();
|
DependencyManager.Instance.RegisterType<FormBlanks>();
|
||||||
|
@ -18,4 +18,8 @@
|
|||||||
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
39
LawFirm/LawFirmBusinessLogic/LogicImplementationExtension.cs
Normal file
39
LawFirm/LawFirmBusinessLogic/LogicImplementationExtension.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using LawFirmBusinessLogic.BusinessLogics;
|
||||||
|
using LawFirmBusinessLogic.MailWorker;
|
||||||
|
using LawFirmBusinessLogic.OfficePackage.Implements;
|
||||||
|
using LawFirmBusinessLogic.OfficePackage;
|
||||||
|
using LawFirmContracts.BusinessLogicContracts;
|
||||||
|
using LawFirmContracts.DI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmBusinessLogic
|
||||||
|
{
|
||||||
|
public class LogicImplementationExtension : ILogicImplementationExtension
|
||||||
|
{
|
||||||
|
public int Priority => 0;
|
||||||
|
|
||||||
|
public void RegisterServices()
|
||||||
|
{
|
||||||
|
DependencyManager.Instance.RegisterType<IBlankLogic, BlankLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IDocumentLogic, DocumentLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||||
|
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(isSingle: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,13 +27,15 @@ namespace LawFirmContracts.DI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void InitDependency()
|
public static void InitDependency()
|
||||||
{
|
{
|
||||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
var extList = ServiceProviderLoader.GetImplementationExtensions();
|
||||||
if (ext == null)
|
foreach (var ext in extList)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
if (ext == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||||
|
}
|
||||||
|
ext.RegisterServices();
|
||||||
}
|
}
|
||||||
// регистрируем зависимости
|
|
||||||
ext.RegisterServices();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -9,34 +9,47 @@ namespace LawFirmContracts.DI
|
|||||||
{
|
{
|
||||||
public class ServiceProviderLoader
|
public class ServiceProviderLoader
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
/// Загрузка всех классов-реализаций IImplementationExtension
|
/// Загрузка всех классов-реализаций IImplementationExtension
|
||||||
public static IImplementationExtension? GetImplementationExtensions()
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static List<IImplementationExtension?> GetImplementationExtensions()
|
||||||
{
|
{
|
||||||
IImplementationExtension? source = null;
|
// Список типов, по каждому из которых, должна быть выбрана наиболее приоритетная реализация
|
||||||
|
// IImplementationExtension должен быть последним, поскольку все классы реализации, наследуются от него и являются им в частности
|
||||||
|
Type[] types =
|
||||||
|
{
|
||||||
|
typeof(ILogicImplementationExtension),
|
||||||
|
typeof(IImplementationExtension)
|
||||||
|
};
|
||||||
|
var trueTypes = types.Select(x => (IImplementationExtension?)null).ToList();
|
||||||
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||||
foreach (var file in files.Distinct())
|
foreach (var file in files.Distinct())
|
||||||
{
|
{
|
||||||
Assembly asm = Assembly.LoadFrom(file);
|
Assembly asm = Assembly.LoadFrom(file);
|
||||||
foreach (var t in asm.GetExportedTypes())
|
foreach (var t in asm.GetExportedTypes())
|
||||||
{
|
{
|
||||||
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
|
for (var i = 0; i < types.Length; i++)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (t.IsClass && types[i].IsAssignableFrom(t))
|
||||||
{
|
{
|
||||||
source = (IImplementationExtension)Activator.CreateInstance(t)!;
|
if (trueTypes[i] == null)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
|
||||||
if (newSource.Priority > source.Priority)
|
|
||||||
{
|
{
|
||||||
source = newSource;
|
trueTypes[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||||
|
if (newSource.Priority > trueTypes[i].Priority)
|
||||||
|
{
|
||||||
|
trueTypes[i] = newSource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return source;
|
return trueTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string TryGetImplementationExtensionsFolder()
|
private static string TryGetImplementationExtensionsFolder()
|
||||||
|
Loading…
Reference in New Issue
Block a user