Frequently Asked Questions
Q. How do I inject all registered implementations of a service in an array? i.e. inject all available IBar in:
public class Foo { public Foo(IBar[] bars) { } }
A. Add the ArrayResolver:
container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));
Q. How do I inject the current IPrincipal into my MVC Controller?
A.
var container = new WindsorContainer(); container.AddFacility<FactorySupportFacility>(); container.Register(Component.For<IPrincipal>() .LifeStyle.PerWebRequest .UsingFactoryMethod(() => HttpContext.Current.User)); // your component registrations...
Q. How do I list all registered components?
A. Use IKernel.GetAssignableHandlers(typeof(object)):
foreach (var handler in container.Kernel.GetAssignableHandlers(typeof(object))) { Console.WriteLine("{0} {1} {1}", handler.ComponentModel.Name, handler.ComponentModel.Service, handler.ComponentModel.Implementation); }
Q. How do I visualize all registered components and their dependencies?
A. See this blog post
.
Q. How do I test that all my registered components can be resolved?
A. See this blog post
.
Q. Is Windsor thread-safe?
A. Yes
Q. How do I change a component's configuration or implementation for debug / staging / production environments?
A. You can pick from several solutions depending on your situation:
- http://stackoverflow.com/questions/962574/castle-windsor-configuration-based-on-build-or-config-file

- http://stackoverflow.com/questions/2053545/castle-windsor-staging-vs-production-connectionstring-parameter-for-a-component

Q. How to prevent Castle Windsor from injecting property dependencies?
A. By default Windsor treats properties as optional dependencies, and it will inject them if the service is available. There are a number of workarounds if you don't want this behavior:
- http://stackoverflow.com/questions/178611/windsor-container-how-to-specify-a-public-property-should-not-be-filled-by-the-c/182002#182002

- http://using.castleproject.org/display/Contrib/Castle.Facilities.OptionalPropertyInjection

- http://jfromaniello.blogspot.com/2009/07/noninjectable-service.html

Q. How do I register two interfaces to the same component?
A. Use type forwarding, see the fluent API page
.
