PIbd-23-Radaev-A.V.-GiftShop/GiftShop/GiftShopContracts/DI/UnityDependencyContainer.cs
Arkadiy Radaev 44fa88599e res8
2024-05-17 13:28:57 +04:00

39 lines
890 B
C#

using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;
namespace GiftShopContracts.DI
{
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);
}
}
}