I’m programmatically registering a group of services that all implement the same interface, IRule. I have another service that looks like this:
public class MyService {
private IEnumerable<IRule> _rules;
public MyService(IEnumerable<IRule> rules){
_rules = rules;
}
}
Hammett posted something that looked like what I wanted, http://hammett.castleproject.org/?p=257. I changed the signature to IRule[] and tried the ArrayResolver trick in the post but that didn’t work for me(note, it didn’t break anything either).
Anyone know how to programmatically register a component like the code I posted above?
I loaded up the source for Castle.MicroKernel, and noticed there is already an ArrayResolver and ListResolver(in the Castle.MicroKernel.Resolvers.SpecializedResolvers namespace). The code I copied(blindly) from Hammet’s blog didn’t work, most likely because the framework had changed since that was written.
Here’s a sample project demonstrating how to do this: http://www.panteravb.com/downloads/WindsorCon.zip
I tried both the ArrayResolver and the ListResolver and they both worked without a hitch, it’s pretty straightforward, so assuming this service class:
you can register this guy like this: