diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs index fd6b156..5c3f776 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/DataGridViewExtension.cs @@ -55,8 +55,11 @@ namespace BlacksmithWorkshop { column.Width = columnAttr.Width; } - } - } + + + column.DefaultCellStyle.Format = columnAttr.Format; + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 36d8270..5ea1d74 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -178,7 +178,7 @@ namespace BlacksmithWorkshop private void ImplementerToolStripMenuItem_Click_1(object sender, EventArgs e) { - var form = DependencyManager.Instance.Resolve(); + var form = DependencyManager.Instance.Resolve(); form.ShowDialog(); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 8b23862..2362d2f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -64,23 +64,6 @@ namespace BlacksmithWorkshop 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(); - DependencyManager.Instance.RegisterType(); - - DependencyManager.Instance.RegisterType(); - DependencyManager.Instance.RegisterType(true); - DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); DependencyManager.Instance.RegisterType(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj index 40f0332..5507a90 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogicImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogicImplementationExtension.cs new file mode 100644 index 0000000..75c998d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogicImplementationExtension.cs @@ -0,0 +1,40 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopBusinessLogic.MailWorker; +using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; +using BlacksmithWorkshopBusinessLogic.OfficePackage; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.DI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic +{ + public class BusinessLogicImplementationExtension : IBusinessLogicImplementationExtension + { + public int Priority => 0; + + 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(); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs index a8837bb..47cf397 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/DependencyManager.cs @@ -45,7 +45,17 @@ namespace BlacksmithWorkshopContracts.DI // регистрируем зависимости ext.RegisterServices(); - } + + var extBusiness = ServiceProviderLoader.GetBusinessLogicImplementationExtensions(); + + if (extBusiness == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + + // регистрируем зависимости + extBusiness.RegisterServices(); + } //Регистрация логгера public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IBusinessLogicImplementationExtension.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IBusinessLogicImplementationExtension.cs new file mode 100644 index 0000000..052ea0e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/IBusinessLogicImplementationExtension.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.DI +{ + public interface IBusinessLogicImplementationExtension + { + public int Priority { get; } + + //Регистрация сервисов + public void RegisterServices(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs index 12929f0..9343eeb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/DI/ServiceProviderLoader.cs @@ -57,5 +57,51 @@ namespace BlacksmithWorkshopContracts.DI return $"{directory?.FullName}\\ImplementationExtensions"; } - } + + public static IBusinessLogicImplementationExtension? GetBusinessLogicImplementationExtensions() + { + IBusinessLogicImplementationExtension? source = null; + + var files = Directory.GetFiles(TryGetBusinessLogicImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IBusinessLogicImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!; + + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + + return source; + } + + private static string TryGetBusinessLogicImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + + while (directory != null && !directory.GetDirectories("BusinessLogicImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicImplementationExtensions")) + { + directory = directory.Parent; + } + + return $"{directory?.FullName}\\BusinessLogicImplementationExtensions"; + } + } } diff --git a/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopBusinessLogic.dll b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopBusinessLogic.dll new file mode 100644 index 0000000..82a2522 Binary files /dev/null and b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopBusinessLogic.dll differ diff --git a/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopContracts.dll b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopContracts.dll new file mode 100644 index 0000000..f00c493 Binary files /dev/null and b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopContracts.dll differ diff --git a/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopDataModels.dll b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopDataModels.dll new file mode 100644 index 0000000..0bc9e09 Binary files /dev/null and b/BlacksmithWorkshop/BusinessLogicImplementationExtensions/BlacksmithWorkshopDataModels.dll differ