53 lines
1.0 KiB
C#
53 lines
1.0 KiB
C#
|
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<ILoggingBuilder> configure)
|
|||
|
{
|
|||
|
ILoggerFactory loggerFactory = LoggerFactory.Create(configure);
|
|||
|
_container.AddExtension(new LoggingExtension(loggerFactory));
|
|||
|
}
|
|||
|
|
|||
|
public void RegisterType<T>(bool isSingle) where T : class
|
|||
|
{
|
|||
|
if (isSingle)
|
|||
|
{
|
|||
|
_container.RegisterType<T>(TypeLifetime.Singleton);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_container.RegisterType<T>();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public T Resolve<T>()
|
|||
|
{
|
|||
|
return _container.Resolve<T>();
|
|||
|
}
|
|||
|
|
|||
|
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
|
|||
|
{
|
|||
|
if (isSingle)
|
|||
|
{
|
|||
|
_container.RegisterType<T, U>(TypeLifetime.Singleton);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_container.RegisterType<T, U>();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|