With StructureMap one can do a resolution and force the container to use specific dependency instance provided at the time of resolution like so:
ObjectFactory.With<ISomeDependency>(someDepedencyInstance).GetInstance<IServiceType>()
Provided instance will be used in whole resolution chain, that is not only as a direct dependency of IServiceType implementation but also as a dependency of any direct and indirect dependencies of IServiceType implementation.
How do I do something like that in Castle Windsor?
I know I can provide a direct dependency with an overload of IWindsorContainer.Resolve<>(), but I need to provide this dependency to something deeper.
You can register an instance as the implementation of a given component like this:
This means that everytime you resolve anything and ISomeDependency is part of the resolved object graph, the
someDependencyInstanceinstance will be used.It that what you want, or did I misunderstand the question?
Based on additional information, here’s a new attempt at answering the question.
You should be able to use container hierarchies for this. If a Windsor container can’t resolve a type, it’ll ask its parent. This means that you can create a child container that contains only the override and then ask that container to resolve the type for you.
Here’s an example:
The resolved
servicewill contain an instance of SomeOtherDependency and not SomeDependency.Notice how
childContaineronly overrides the registration of ISomeDependency. All other registrations are used from the parent.