2023-04-23 11:06:54 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace FurnitureAssemblyContracts.DI
|
|
|
|
|
{
|
|
|
|
|
public class DependencyManager
|
|
|
|
|
{
|
|
|
|
|
private readonly IDependencyContainer _dependencyManager;
|
|
|
|
|
private static DependencyManager? _manager;
|
|
|
|
|
private static readonly object _locjObject = new();
|
|
|
|
|
private DependencyManager()
|
|
|
|
|
{
|
|
|
|
|
_dependencyManager = new ServiceDependencyContainer();
|
|
|
|
|
}
|
|
|
|
|
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 == null)
|
|
|
|
|
{
|
2023-04-23 14:54:27 +04:00
|
|
|
|
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (хранилище)");
|
2023-04-23 11:06:54 +04:00
|
|
|
|
}
|
|
|
|
|
// регистрируем зависимости
|
|
|
|
|
ext.RegisterServices();
|
2023-04-23 14:54:27 +04:00
|
|
|
|
|
|
|
|
|
var extBL = ServiceProviderLoader.GetImplementationBusinessLogicExtensions();
|
|
|
|
|
if (extBL == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям (бизнес-логика)");
|
|
|
|
|
}
|
|
|
|
|
extBL.RegisterServices();
|
2023-04-23 11:06:54 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Регистрация логгера
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configure"></param>
|
|
|
|
|
public void AddLogging(Action<ILoggingBuilder> configure) =>
|
|
|
|
|
_dependencyManager.AddLogging(configure);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление зависимости
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <typeparam name="U"></typeparam>
|
|
|
|
|
public void RegisterType<T, U>(bool isSingle = false) where U :
|
|
|
|
|
class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление зависимости
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <typeparam name="U"></typeparam>
|
|
|
|
|
public void RegisterType<T>(bool isSingle = false) where T : class =>
|
|
|
|
|
_dependencyManager.RegisterType<T>(isSingle);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение класса со всеми зависмостями
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|