using System; using Castle.MicroKernel.Registration; using Castle.Windsor; namespace Tapeti.CastleWindsor { /// /// Dependency resolver and container implementation for Castle Windsor. /// public class WindsorDependencyResolver : IDependencyContainer { private readonly IWindsorContainer container; /// /// public WindsorDependencyResolver(IWindsorContainer 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 { // No need for anything special to register as default, because "In Windsor first one wins": // https://github.com/castleproject/Windsor/blob/master/docs/registering-components-one-by-one.md container.Register( Component .For() .ImplementedBy() ); } /// public void RegisterDefault(Func factory) where TService : class { container.Register( Component .For() .UsingFactoryMethod(factory) ); } /// public void RegisterDefaultSingleton() where TService : class where TImplementation : class, TService { container.Register( Component .For() .ImplementedBy() .LifestyleSingleton() ); } /// public void RegisterDefaultSingleton(TService instance) where TService : class { container.Register( Component .For() .Instance(instance) ); } /// public void RegisterDefaultSingleton(Func factory) where TService : class { container.Register( Component .For() .UsingFactoryMethod(factory) .LifestyleSingleton() ); } /// public void RegisterController(Type type) { container.Register(Component.For(type)); } } }