using System; using Unity; using Unity.Lifetime; namespace Tapeti.UnityContainer { /// /// /// Dependency resolver and container implementation for SimpleInjector. /// public class UnityDependencyResolver : IDependencyContainer { private readonly IUnityContainer container; /// /// public UnityDependencyResolver(IUnityContainer container) { this.container = container; } /// public T Resolve() where T : class { return container.Resolve(); } /// public object Resolve(Type type) { return container.Resolve(type); } /// public void RegisterDefault() where TService : class where TImplementation : class, TService { if (container.IsRegistered(typeof(TService))) return; container.RegisterType(); } /// public void RegisterDefault(Func factory) where TService : class { if (container.IsRegistered(typeof(TService))) return; container.RegisterFactory(c => factory()); } /// public void RegisterDefaultSingleton() where TService : class where TImplementation : class, TService { if (container.IsRegistered(typeof(TService))) return; container.RegisterSingleton(); } /// public void RegisterDefaultSingleton(TService instance) where TService : class { if (container.IsRegistered(typeof(TService))) return; container.RegisterInstance(instance); } /// public void RegisterDefaultSingleton(Func factory) where TService : class { if (container.IsRegistered(typeof(TService))) return; container.RegisterFactory(c => factory(), new SingletonLifetimeManager()); } /// public void RegisterController(Type type) { container.RegisterType(type); } } }