From a392caad33e6a0207af05a11d3c02d8209a37e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 22:21:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B4=D0=B0=D0=B0=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryContracts.csproj | 3 ++ .../DI/UnityDependencyContainer.cs | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ConfectioneryContracts/DI/UnityDependencyContainer.cs diff --git a/ConfectioneryContracts/ConfectioneryContracts.csproj b/ConfectioneryContracts/ConfectioneryContracts.csproj index 09a95fc..2ccddfa 100644 --- a/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -9,6 +9,9 @@ + + + diff --git a/ConfectioneryContracts/DI/UnityDependencyContainer.cs b/ConfectioneryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..dd5e085 --- /dev/null +++ b/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -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 configure) + { + var factory = _container.Configure().LoggerFactory; + _container.Configure(); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +}