Реализовал внедрение зависимостей
This commit is contained in:
parent
9b1c5ce5b9
commit
d1b5b642ec
@ -1,7 +1,15 @@
|
||||
using InternetShopContracts.LogicsContracts;
|
||||
using InternetShopContracts.StorageContracts;
|
||||
using InternetShopDatabase.Storages;
|
||||
using InternetShopLogics.Logics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace InternetShopForms
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -11,7 +19,20 @@ namespace InternetShopForms
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormOrdersList());
|
||||
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormOrdersList>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IProductStorage, ProductStorage>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IProductLogic, ProductLogic>();
|
||||
services.AddTransient<FormOrdersList>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user