PIbd-21. Rodionov I.A. Lab work 08 #12

Closed
ILRodionov wants to merge 4 commits from lab8_base into lab7_base
3 changed files with 41 additions and 2 deletions
Showing only changes of commit 5797844543 - Show all commits

View File

@ -12,8 +12,8 @@ namespace IceCreamShopContracts.DI
private DependencyManager()
{
_dependencyManager = new ServiceDependencyContainer();
}
_dependencyManager = new UnityDependencyContainer();
}
public static DependencyManager Instance { get { if (_manager == null) { lock (_lockObject) { _manager = new DependencyManager(); } } return _manager; } }

View File

@ -0,0 +1,37 @@
using Microsoft.Extensions.Logging;
using Unity.Microsoft.Logging;
using Unity;
namespace IceCreamShopContracts.DI
{
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));
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
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>();
}
}
}

View File

@ -8,6 +8,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>