Reputation: 8343
I cannot get Castle Windsor (3.0) to resolve an array. I've done it before and I have other arrays resolved, so this is confounding.
First I add a CollectionResolver
, which does arrays
_container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel));
Then, I register all my classes based on this interface, of which there are about 6
container.Register(AllTypes.FromThisAssembly().BasedOn<ISearchSource>());
They are definitely in the same assembly and in the debugger, I can see these classes are in the list of components eg.
public class ViewsSearchSource : ISearchSource {...}
Yet in the class that resolves this, like this...
public SearchBot(ISearchSource[] searchSources)
I get
'SearchBot' is waiting for the following dependenciesService 'ISearchSource[]' which was not registered.
I've even tried adding an ArrayResolver
(as well as CollectionResolver
) explicitly. Same error.
What am I missing here?
Upvotes: 0
Views: 619
Reputation: 3070
AllInterfaces is necessary due to your dependency is on interface type: "AllTypes.FromThisAssembly().BasedOn()" picks all types implementing ISearchSource, but those types will be registered in the container with the concrete type, not with the interface(which has been used instead as dependency).
PS: I suggest you to use Classes instead of AllTypes.
"WithServiceDefaultInterfaces()" should be enough in your case.
Keep in mind windsor resolves dependencies according to registration: IOW you have to flag(during component registration) your concrete with all its interface you will use as dependency.
While you are in debug, add a watch/breakpoint on the container to see all registered component and the interface/concrete "linked/assigned" to you component: that unveil the magic behind the resolution.
Upvotes: 1
Reputation: 8343
I needed to register like this
container.Register(AllTypes.FromThisAssembly().BasedOn<ISearchSource>().WithService.AllInterfaces());
ie had to add WithService.AllInterfaces());
I actually don't understand why this AllInterfaces is necessary here, but it works.
Upvotes: 0