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); + } + } +}