Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor CollectionResolver: Why doesn't it work on Resolve calls?

I've added the CollectionResolver as a sub-resolver of my Windsor kernel, and it will properly inject collections of dependencies on resolved objects. That is, if I have

class X { public X(IComponent[] components) { ... } }
container.Register(/* lots of IComponents */);
container.Register(Component.For<X>());

the components argument to the constructor is properly constructed when I resolve it

container.Resolve<X>()

but if instead I'd just like to get the list of components themselves,

container.Resolve<IComponent[]>()

I get a ComponentNotFound exception complaining that I have not registered any components for IComponent[]. I find this asymmetry counterintuitive as I'm not sure why the kernel should act differently when it is resolving dependencies it found on constructors/properties as compared to when it is resolving dependencies its user would like it to resolve.

like image 219
Sebastian Good Avatar asked May 03 '11 05:05

Sebastian Good


1 Answers

The explicit division for Resolve/ResolveAll is due to internal and uninteresting implementation details in the container. The collection resolver is a sub depenendcy resolver and as such it only works for dependencies.

I agree it is not really intuitive. Feel free to log a ticket into Windsor's issue tracker about it.

like image 170
Krzysztof Kozmic Avatar answered Nov 17 '22 01:11

Krzysztof Kozmic