Поменял на всех формах код внедрения зависимостей
This commit is contained in:
parent
0484b22e03
commit
2bacaad2c3
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,3 +398,4 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
ImplementationExtensions/
|
@ -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<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfoStorage, BackUpInfoStorage>();
|
||||
}
|
||||
}
|
||||
}
|
@ -21,4 +21,8 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -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<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfoStorage, BackUpInfoStorage>();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,4 +12,8 @@
|
||||
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,17 @@
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
|
||||
namespace SecuritySystemListImplement.Implements
|
||||
{
|
||||
public class BackUpInfoStorage : IBackUpInfoStorage
|
||||
{
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfoStorage, BackUpInfoStorage>();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,4 +12,8 @@
|
||||
<ProjectReference Include="..\SecuritySystemDataModels\SecuritySystemDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -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<FormComponent>();
|
||||
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<FormComponent>();
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -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<FormComponents>();
|
||||
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<FormSecures>();
|
||||
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<FormCreateOrder>();
|
||||
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<FormReportSecureComponents>();
|
||||
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<FormReportOrders>();
|
||||
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<FormClients>();
|
||||
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<FormImplementers>();
|
||||
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<IImplementerLogic>())!, _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<FormMails>();
|
||||
if (service is FormMails form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -232,7 +232,6 @@ namespace SecuritySystemView
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<FormImplementer>();
|
||||
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<FormImplementer>();
|
||||
if (service is FormImplementer form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
@ -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<AbstractMailWorker>();
|
||||
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
|
||||
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<ILogger>();
|
||||
var logger = DependencyManager.Instance.Resolve<ILogger>();
|
||||
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||
}
|
||||
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
|
||||
}
|
||||
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<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ISecureStorage, SecureStorage>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
services.AddTransient<IBackUpInfoStorage, BackUpInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<ISecureStorage, SecureStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfoStorage, BackUpInfoStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ISecureLogic, SecureLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
services.AddTransient<IBackUpLogic, BackUpLogic>();
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<ISecureLogic, SecureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormSecure>();
|
||||
services.AddTransient<FormSecureComponent>();
|
||||
services.AddTransient<FormSecures>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormReportSecureComponents>();
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
services.AddTransient<FormImplementers>();
|
||||
services.AddTransient<FormMails>();
|
||||
DependencyManager.Instance.RegisterType<FormMain>();
|
||||
DependencyManager.Instance.RegisterType<FormComponent>();
|
||||
DependencyManager.Instance.RegisterType<FormComponents>();
|
||||
DependencyManager.Instance.RegisterType<FormCreateOrder>();
|
||||
DependencyManager.Instance.RegisterType<FormSecure>();
|
||||
DependencyManager.Instance.RegisterType<FormSecureComponent>();
|
||||
DependencyManager.Instance.RegisterType<FormSecures>();
|
||||
DependencyManager.Instance.RegisterType<FormReportOrders>();
|
||||
DependencyManager.Instance.RegisterType<FormReportSecureComponents>();
|
||||
DependencyManager.Instance.RegisterType<FormClients>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementer>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementers>();
|
||||
DependencyManager.Instance.RegisterType<FormMails>();
|
||||
}
|
||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
||||
}
|
||||
|
@ -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<FormSecureComponent>();
|
||||
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<FormSecureComponent>();
|
||||
if (service is FormSecureComponent form)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
|
@ -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<FormSecure>();
|
||||
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<FormSecure>();
|
||||
if (service is FormSecure form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
Loading…
Reference in New Issue
Block a user