2021-03-28 19:48:15 +04:00
|
|
|
|
using ModuleTools.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace ModuleTools.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Менеджер для работы с зависимостями
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DependencyManager
|
|
|
|
|
{
|
|
|
|
|
private readonly IDependencyManager _dependencyManager;
|
|
|
|
|
|
|
|
|
|
private static DependencyManager _manager;
|
|
|
|
|
|
|
|
|
|
private static readonly object _locjObject = new object();
|
|
|
|
|
|
|
|
|
|
private DependencyManager()
|
|
|
|
|
{
|
|
|
|
|
_dependencyManager = new UnityContainerManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Иницализация библиотек, в которых идут установки зависомстей
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void InitDependency()
|
|
|
|
|
{
|
|
|
|
|
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
|
|
|
|
if (ext.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
|
|
|
|
}
|
|
|
|
|
// регистрируем зависимости
|
|
|
|
|
foreach (var e in ext)
|
|
|
|
|
{
|
|
|
|
|
e.RegisterServices();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление зависимости
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <typeparam name="U"></typeparam>
|
|
|
|
|
public void RegisterType<T, U>() where U : T => _dependencyManager.RegisterType<T, U>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление зависимости
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public void RegisterType<T>() => _dependencyManager.RegisterType<T>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение класса со всеми зависмостями
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
2021-03-30 22:34:31 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение класса со всеми зависмостями
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public object Resolve(Type t) => _dependencyManager.Resolve(t);
|
2021-03-28 19:48:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|