PIbd-23-Salin-O.A.-IceCream.../IceCreamShop/IceCreamShopContracts/DI/DependencyManager.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2024-05-12 13:29:49 +04:00
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IceCreamShopContracts.DI
{
public class DependencyManager
{
private readonly IDependencyContainer _dependencyManager;
private static DependencyManager? _manager;
private static readonly object _locjObject = new();
private DependencyManager()
{
_dependencyManager = new UnityDependencyContainer();
2024-05-12 13:29:49 +04:00
}
public static DependencyManager Instance
{
get
{
if (_manager ==
null) { lock (_locjObject) { _manager = new DependencyManager(); } }
return
_manager;
}
}
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
{
throw new ArgumentNullException("Отсутствуют компонент для загрузки зависимостей по модулям");
}
ext.RegisterServices();
}
public void AddLogging(Action<ILoggingBuilder> configure) =>
_dependencyManager.AddLogging(configure);
public void RegisterType<T, U>(bool isSingle = false) where U :
class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
public void RegisterType<T>(bool isSingle = false) where T : class =>
_dependencyManager.RegisterType<T>(isSingle);
public T Resolve<T>() => _dependencyManager.Resolve<T>();
}
}