What if one of your components depend on an array or a IEnumerable. Consider following scenario:
In Castle Windsor you need to opt-in for this behavior before registering components, so the container knows you want this behavior.
This will work if your TaskExecutor is depending on an IEnumerable, ICollection, IList or an array of ITask. The second constructor parameter of CollectionResolver determines if Windsor allows empty collections, so if the value is true it will not throw an exception if you have no components registered.
You need to opt-in before registering any components otherwise it will not work!
As this does not exist out of the box and it is so important to opt-in before registering any components, let’s create our first facility. A facility is more or less an extension of Castle.Windsor.
Now next time you need to have collection dependencies you will just need to add the facility to Windsor like this:
What if you needed to resolve a Func ? You could just do this, albeit a little bit cumbersome:
What if you wanted this behavior out of the box without registering every delegate by hand: use the power of TypedFactoryFacility:
Last but not least how to use Lazy, a recent addition to Castle Windsor (as of version 3)
Next time i will try to elaborate on the trough power of the TypedFactoryFacility, i hope you are liking the series so far. Remember your feedback is important!