PIbd-22_Chernyshev_G.Y._LabWork08_Base #9
@ -17,8 +17,7 @@ namespace GarmentFactoryContracts.DependencyInjection
|
||||
private static readonly object _locjObject = new();
|
||||
private DependencyManager()
|
||||
{
|
||||
//ПОМЕНЯТЬ НА UNITY реализацию
|
||||
_dependencyManager = new ServiceDependencyContainer();
|
||||
_dependencyManager = new UnityDependencyContainer();
|
||||
}
|
||||
public static DependencyManager Instance
|
||||
{
|
||||
|
@ -0,0 +1,43 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace GarmentFactoryContracts.DependencyInjection
|
||||
{
|
||||
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
|
||||
{
|
||||
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
|
||||
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
|
||||
{
|
||||
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user