diff --git a/.gitignore b/.gitignore index ca1c7a3..4f51ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +ImplementationExtensions/ \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/DatabaseImplementationExtension .cs b/SecuritySystem/SecuritySystemDatabaseImplement/DatabaseImplementationExtension .cs new file mode 100644 index 0000000..b8fa178 --- /dev/null +++ b/SecuritySystem/SecuritySystemDatabaseImplement/DatabaseImplementationExtension .cs @@ -0,0 +1,21 @@ +using SecuritySystemContracts.DI; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemDatabaseImplement.Implements; + +namespace SecuritySystemDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabaseImplement.csproj b/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabaseImplement.csproj index f2838d1..453e6f5 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabaseImplement.csproj +++ b/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabaseImplement.csproj @@ -1,24 +1,28 @@  - - net6.0 - enable - enable - AnyCPU;x64 - + + net6.0 + enable + enable + AnyCPU;x64 + - - - - + + + + - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + diff --git a/SecuritySystem/SecuritySystemFileImplement/FileImplementationExtension .cs b/SecuritySystem/SecuritySystemFileImplement/FileImplementationExtension .cs new file mode 100644 index 0000000..737e734 --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/FileImplementationExtension .cs @@ -0,0 +1,21 @@ +using SecuritySystemContracts.DI; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemFileImplement.Implements; + +namespace SecuritySystemFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/SecuritySystem/SecuritySystemFileImplement/SecuritySystemFileImplement.csproj b/SecuritySystem/SecuritySystemFileImplement/SecuritySystemFileImplement.csproj index 2c64771..335113d 100644 --- a/SecuritySystem/SecuritySystemFileImplement/SecuritySystemFileImplement.csproj +++ b/SecuritySystem/SecuritySystemFileImplement/SecuritySystemFileImplement.csproj @@ -1,15 +1,19 @@ - - net6.0 - enable - enable - AnyCPU;x64;x86 - + + net6.0 + enable + enable + AnyCPU;x64;x86 + - - - - + + + + + + + + diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/BackUpInfoStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/BackUpInfoStorage.cs new file mode 100644 index 0000000..f0441b3 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/BackUpInfoStorage.cs @@ -0,0 +1,17 @@ +using SecuritySystemContracts.StoragesContracts; + +namespace SecuritySystemListImplement.Implements +{ + public class BackUpInfoStorage : IBackUpInfoStorage + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/ListImplementationExtension.cs b/SecuritySystem/SecuritySystemListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..686b7f2 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/ListImplementationExtension.cs @@ -0,0 +1,21 @@ +using SecuritySystemContracts.DI; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemListImplement.Implements; + +namespace SecuritySystemListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + 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(); + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj index 64fda98..90a5015 100644 --- a/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj +++ b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/SecuritySystem/SecuritySystemView/Component/FormComponents.cs b/SecuritySystem/SecuritySystemView/Component/FormComponents.cs index 9acae52..e059195 100644 --- a/SecuritySystem/SecuritySystemView/Component/FormComponents.cs +++ b/SecuritySystem/SecuritySystemView/Component/FormComponents.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; using System.Windows.Forms; namespace SecuritySystemView @@ -35,7 +36,7 @@ namespace SecuritySystemView } private void ButtonAddComponent_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -48,7 +49,7 @@ namespace SecuritySystemView { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponent form) { form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs index 99763b3..b32ef1f 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; -using SecuritySystemBusinessLogic.BusinessLogics; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; using SecuritySystemView.Client; using SecuritySystemView.Implementer; using SecuritySystemView.Mail; @@ -49,7 +49,7 @@ namespace SecuritySystemView } private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormComponents form) { form.ShowDialog(); @@ -57,7 +57,7 @@ namespace SecuritySystemView } private void SecuresToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSecures)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSecures form) { form.ShowDialog(); @@ -65,7 +65,7 @@ namespace SecuritySystemView } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -162,7 +162,7 @@ namespace SecuritySystemView private void ReportComponentsSecuresToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSecureComponents)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportSecureComponents form) { form.ShowDialog(); @@ -171,7 +171,7 @@ namespace SecuritySystemView private void ReportOrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -180,7 +180,7 @@ namespace SecuritySystemView private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -189,7 +189,7 @@ namespace SecuritySystemView private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -198,13 +198,13 @@ namespace SecuritySystemView private void StartWorksToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork((DependencyManager.Instance.Resolve())!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMails form) { form.ShowDialog(); @@ -232,7 +232,6 @@ namespace SecuritySystemView { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } } } diff --git a/SecuritySystem/SecuritySystemView/Implementer/FormImplementers.cs b/SecuritySystem/SecuritySystemView/Implementer/FormImplementers.cs index aef6cfb..01cb14b 100644 --- a/SecuritySystem/SecuritySystemView/Implementer/FormImplementers.cs +++ b/SecuritySystem/SecuritySystemView/Implementer/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; namespace SecuritySystemView.Implementer { @@ -33,7 +34,7 @@ namespace SecuritySystemView.Implementer } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -46,7 +47,7 @@ namespace SecuritySystemView.Implementer { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index ba35717..7e1961b 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -7,6 +7,7 @@ using SecuritySystemBusinessLogic.OfficePackage; using SecuritySystemBusinessLogic.OfficePackage.Implements; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; using SecuritySystemContracts.StoragesContracts; using SecuritySystemDatabaseImplement.Implements; using SecuritySystemView.Client; @@ -30,12 +31,11 @@ namespace SecuritySystemView // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -49,56 +49,57 @@ namespace SecuritySystemView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + 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(); } private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } diff --git a/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs index 7083b18..453e59f 100644 --- a/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; using SecuritySystemContracts.SearchModels; using SecuritySystemDataModels.Models; using System.Windows.Forms; @@ -73,7 +74,7 @@ namespace SecuritySystemView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSecureComponent form) { if (form.ShowDialog() == DialogResult.OK) @@ -101,7 +102,7 @@ namespace SecuritySystemView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSecureComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs index 1516778..f5b8add 100644 --- a/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.DI; namespace SecuritySystemView { @@ -34,7 +35,7 @@ namespace SecuritySystemView } private void ButtonAddSecure_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSecure form) { if (form.ShowDialog() == DialogResult.OK) @@ -47,7 +48,7 @@ namespace SecuritySystemView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSecure)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSecure form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);