using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Unity; using Unity.Microsoft.Logging; namespace SewingDressesContracts.DI { public class DependencyContainerUnity : IDependencyContainer { private readonly IUnityContainer _container; public DependencyContainerUnity() { _container = new UnityContainer(); } public void AddLogging(Action configure) { ILoggerFactory loggerFactory = LoggerFactory.Create(configure); _container.AddExtension(new LoggingExtension(loggerFactory)); } public void RegisterType(bool isSingle) where T : class { if (isSingle) { _container.RegisterType(TypeLifetime.Singleton); } else { _container.RegisterType(); } } public T Resolve() { return _container.Resolve(); } void IDependencyContainer.RegisterType(bool isSingle) { if (isSingle) { _container.RegisterType(TypeLifetime.Singleton); } else { _container.RegisterType(); } } } }