using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;

namespace BarContracts.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 IsSingleton) where T : class
		{
			_container.RegisterType<T>(IsSingleton ? TypeLifetime.Singleton : TypeLifetime.Transient);

		}
		
		public T Resolve<T>()
		{
			return _container.Resolve<T>();
		}
		
		void IDependencyContainer.RegisterType<T, U>(bool IsSingleton)
		{
			_container.RegisterType<T, U>(IsSingleton ? TypeLifetime.Singleton : TypeLifetime.Transient);
		}
	}
}
