diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 0c9d8bc..1e2e879 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -67,22 +67,6 @@ namespace FurnitureAssembly option.AddNLog("nlog.config"); }); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - - DependencyManager.Instance.RegisterType(true); - - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs new file mode 100644 index 0000000..eae3a4f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogicImplementationExtension.cs @@ -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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj index 92c1d36..b2c7842 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs index 6b99863..6be1b4c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/DependencyManager.cs @@ -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(); } /// /// Регистрация логгера diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..084a213 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/IImplementationBusinessLogicExtension.cs @@ -0,0 +1,6 @@ +namespace FurnitureAssemblyContracts.DI +{ + public interface IImplementationBusinessLogicExtension : IImplementationExtension + { + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs index 6778099..a1ec41c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/DI/ServiceProviderLoader.cs @@ -48,5 +48,52 @@ namespace FurnitureAssemblyContracts.DI } return $"{directory?.FullName}\\ImplementationExtensions"; } + + /// + /// Загрузка всех классов-реализаций IImplementationBLExtension (бизнес-логика) + /// + /// + 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"; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index 8157048..3a99152 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -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;