using System;
using Unity;
using Unity.Lifetime;
namespace ModelTools.BusinessLogics
{
public class UnityContainerConfigurator
{
private static IUnityContainer _unityContainer;
public static IUnityContainer Container
{
get
{
if (_unityContainer == null) _unityContainer = new UnityContainer();
return _unityContainer;
}
}
///
/// Инициализация сервисов
///
public static void InitServices()
{
var ext = ServiceProviderLoader.GetLoaderExtensions();
if (ext.Count == 0)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
// регистрируем в UnityContainaer зависимости
foreach (var e in ext)
{
e.RegisterServices();
}
}
public static void PublishService() where U : T => Container.RegisterType(new HierarchicalLifetimeManager());
public static void PublishService() => Container.RegisterType(new HierarchicalLifetimeManager());
public static T Resolve() => Container.Resolve();
}
}