PIbd-22_Isaeva_A.I._FishFac.../FishFactoryContracts/DependencyInjection/UnityDependencyContainer.cs

39 lines
910 B
C#
Raw Normal View History

2024-06-18 15:56:18 +04:00
using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;
namespace FishFactoryContracts.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);
}
}
}