Dashboard > MicroKernel/Windsor > Home > FAQ
Log In   View a printable version of the current page.
Added by Mauricio Scheffer, last edited by Mauricio Scheffer on Feb 04, 2010  (view change)
Labels: 
(None)


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:

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:

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

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators