59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Unity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity.Microsoft.Logging;
|
|
|
|
|
|
namespace FurnitureAssemblyContracts.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
|
|
{
|
|
if (isSingle)
|
|
{
|
|
container.RegisterSingleton<T>();
|
|
}
|
|
else
|
|
{
|
|
container.RegisterType<T>();
|
|
}
|
|
}
|
|
|
|
public T Resolve<T>()
|
|
{
|
|
return container.Resolve<T>();
|
|
}
|
|
|
|
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
|
|
{
|
|
if (isSingle)
|
|
{
|
|
container.RegisterSingleton<T, U>();
|
|
}
|
|
else
|
|
{
|
|
container.RegisterType<T, U>();
|
|
}
|
|
}
|
|
}
|
|
}
|