Этап 2. Зависимости (бизнес-логика)
This commit is contained in:
parent
11bd076201
commit
34d42994ea
@ -67,22 +67,6 @@ namespace FurnitureAssembly
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IFurnitureLogic, FurnitureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<FormMain>();
|
||||
DependencyManager.Instance.RegisterType<FormComponent>();
|
||||
|
@ -0,0 +1,39 @@
|
||||
using FurnitureAssemblyBusinessLogic.MailWorker;
|
||||
using FurnitureAssemblyBusinessLogic.OfficePackage.Implements;
|
||||
using FurnitureAssemblyBusinessLogic.OfficePackage;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
|
||||
using FurnitureAssemblyContracts.DI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic
|
||||
{
|
||||
public class BusinessLogicImplementationExtension : IImplementationBusinessLogicExtension
|
||||
{
|
||||
public int Priority => 3;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IFurnitureLogic, FurnitureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,4 +20,8 @@
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(targetDir)*.dll" "$(solutionDir)ImplementationBLExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -28,10 +28,17 @@ namespace FurnitureAssemblyContracts.DI
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (хранилище)");
|
||||
}
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
|
||||
var extBL = ServiceProviderLoader.GetImplementationBusinessLogicExtensions();
|
||||
if (extBL == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (бизнес-логика)");
|
||||
}
|
||||
extBL.RegisterServices();
|
||||
}
|
||||
/// <summary>
|
||||
/// Регистрация логгера
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
public interface IImplementationBusinessLogicExtension : IImplementationExtension
|
||||
{
|
||||
}
|
||||
}
|
@ -48,5 +48,52 @@ namespace FurnitureAssemblyContracts.DI
|
||||
}
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка всех классов-реализаций IImplementationBLExtension (бизнес-логика)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IImplementationBusinessLogicExtension? GetImplementationBusinessLogicExtensions()
|
||||
{
|
||||
IImplementationBusinessLogicExtension? source = null;
|
||||
var files = Directory.GetFiles(TryGetImplementationBLExtensionsFolder(), "*.dll",
|
||||
SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass &&
|
||||
typeof(IImplementationBusinessLogicExtension).IsAssignableFrom(t))
|
||||
{
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
source = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
private static string TryGetImplementationBLExtensionsFolder()
|
||||
{
|
||||
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
while (directory != null && !directory.GetDirectories("ImplementationBLExtensions",
|
||||
SearchOption.AllDirectories).Any(x => x.Name == "ImplementationBLExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
return $"{directory?.FullName}\\ImplementationBLExtensions";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
[Column(title: "Название магазина", isUseAutoSize: true, gridViewAutoSize: GridViewAutoSize.Fill)]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
Loading…
Reference in New Issue
Block a user