Passing arguments
It is not always possible to have the container push (inject) all dependencies into your components. Sometimes you'll find yourself needing to pull from the container, passing some arguments in. Windsor lets you do that using
Arguments class, or any custom
IDictionary. How you'll use it, should depend on how and when the value shall be passed.
Composition root - container.Resolve
The
container.Resolve method has several overloads that let you pass in arguments as
IDictionary (in which case it is advised to use
Arguments class), or named arguments as anonymous object.
Don't reference the container directly
It is advised to resist the temptation and use this approach everywhere passing the container around. Use this approach only in your composition root to resolve the root components (see
Three Calls Pattern). In other cases, try to go with one of the other approaches.
Inline dependencies don't get propagated
Whatever arguments you pass to
Resolve method will only be available to the root component you're trying to resolve, and its
Interceptors. All the components further down (root's dependencies, and their dependencies and so on) will not have access to them.
Registration time - DependsOn and DynamicParameters¶
When the value you want to pass in can be known at registration time, or at registration time you have all the information required to obtain it later at call time you can plug directly into registration API and provide the value from there, without any explicit knowledge of the call site. See
here for more details.
Resolution time - typed factories
When you need information from the call site to obtain the component use typed factories to request the objects. See
here for more details.
See also