мдааа

This commit is contained in:
Данияр Аглиуллов 2023-03-18 22:21:03 +04:00
parent 796505fe3b
commit a392caad33
2 changed files with 42 additions and 0 deletions

View File

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

View File

@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;
namespace ConfectioneryContracts.DI
{
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
_container.AddExtension(new LoggingExtension());
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = _container.Configure<LoggingExtension>().LoggerFactory;
_container.Configure<LoggingExtension>();
}
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);
}
}
}