Windsor is an Inversion of Control Container, that means you generally don't call it, and most of your app should be unaware of/oblivious to its presence. Interaction with the container (actually calling any methods on the container) is limited to three points in your application lifetime:
- When the app starts (
Main
,Application_Start
etc) you create the container, and call itsInstall
method. Once. Notice you should only have one instance of the container. - Then at single point (in
Main
,ControllerFactory
etc) you are allowed to callResolve
. If you need to callback to the container to pull some additional dependencies later on, use typed factories. - When your application ends you call
Dispose
on the container to let it clean up and release all the components.
- More in-depth discussion of how to interact with the container
- Inversion of Control
- Windsor Installers
- Fluent Registration API
- Typed Factory Facility
- Blog post by Nicholas Blumhardt explaining thought process behind this usage (Dec 26, 2008)
- Blog post by Krzysztof Koźmic introducing container usage (in push scenarios) (Jun 20, 2010
- Blog post by Krzysztof Koźmic explaining container usage (in pull scenarios) (Jun 22, 2010
Because your components aren't supposed to be calling Windsor. This goes against the very principle of Inversion of Control. Or from practical point of view - will cause you pain and is a decision you'll regret.
See the first question.
Windsor, by default tracks all components to ensure proper lifecycle management, in particular ensure that all IDisposable
components and their dependencies will be properly disposed. You can tell Windsor to stop tracking components by setting its release policy to NoTrackingReleasePolicy
but be aware that this is discouraged, and you're giving up proper lifecycle management by doing so.
Windsor, by default when you have dependency on IFoo[]
, IEnumerable<IFoo>
or IList<IFoo>
will check if you have a component registered for that exact type (array or list of IFoo
), not if you have any components registered for IFoo
(array of components, is not the same as a component which is an array). You can change the behavior to say "When you see array or list of IFoo
just give me all IFoo
s you can get" you use CollectionResolver
. See Resolvers.
Yes, you can. This ability is called forwarded types.
Yes, you can. However you will have to give the components unique names.
Because that leads to more problems than it solves. There's no good default for how such components should be configured. Also doing this might actually mask problems in your registration - you might have wanted to register a type, forget to do so, and then get mis-configured objects.
Having said that - there is a way to resolve components without registering them by using Lazy Component Loaders, and Windsor (some facilities to be precise, like WCF Integration Facility and Typed Factory Facility) take advantage of that. You can too, but it's you who sets the rules for how that objects should be configured, not the container.
No, it can't.
No, it's not. null
means no value and is ignored by Windsor. Be explicit - if the value is optional provide overloaded constructor that does not include it. Alternatively specify explicitly null
as the default value in the signature of the constructor. This is the only scenario where Windsor will allow passing null.