Залил лаб 8

This commit is contained in:
ujijrujijr 2024-05-07 21:21:23 +04:00
parent 464f2bd9e3
commit 6af6dbafc1
3 changed files with 46 additions and 2 deletions

View File

@ -17,8 +17,7 @@ namespace GarmentFactoryContracts.DependencyInjection
private static readonly object _locjObject = new();
private DependencyManager()
{
//ПОМЕНЯТЬ НА UNITY реализацию
_dependencyManager = new ServiceDependencyContainer();
_dependencyManager = new UnityDependencyContainer();
}
public static DependencyManager Instance
{

View File

@ -0,0 +1,43 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Unity.Microsoft.Logging;
namespace GarmentFactoryContracts.DependencyInjection
{
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}
}

View File

@ -8,6 +8,8 @@
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>