Создание и подключение контейнера

This commit is contained in:
Павел Ладягин 2024-11-17 13:40:59 +04:00
parent 0f57d551c7
commit 99d1bee2ed
2 changed files with 23 additions and 1 deletions

View File

@ -8,4 +8,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Unity" Version="5.11.10" />
</ItemGroup>
</Project> </Project>

View File

@ -1,3 +1,7 @@
using FuelAndLubricants.Repositories;
using FuelAndLubricants.Repositories.Implementations;
using Unity;
namespace FuelAndLubricants namespace FuelAndLubricants
{ {
internal static class Program internal static class Program
@ -11,7 +15,21 @@ namespace FuelAndLubricants
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(CreateContainer().Resolve<Form1>());
}
private static UnityContainer CreateContainer()
{
var container = new UnityContainer();
container.RegisterType<ICarRepository, CarRepository>();
container.RegisterType<IDriverRepository, DriverRepository>();
container.RegisterType<IFuelRepository, FuelRepository>();
container.RegisterType<IRefillRepository, RefillRepository>();
container.RegisterType<IRouteRepository, RouteRepository>();
container.RegisterType<ITripRepository, TripRepository>();
return container;
} }
} }
} }