Resolving IEnumerable<T> with Unity
- by Mark Seemann
Can Unity automatically resolve IEnumerable<T>?
Let's say I have a class with this constructor:
public CoalescingParserSelector(IEnumerable<IParserBuilder> parserBuilders)
and I configure individual IParserBuilder instances in the container:
container.RegisterType<IParserSelector, CoalescingParserSelector>();
container.RegisterType<IParserBuilder, HelpParserBuilder>();
container.RegisterType<IParserBuilder, SomeOtherParserBuilder>();
can I make this work without having to implement a custom implementation of IEnumerable<IParserBuilder>?
var selector = container.Resolve<IParserSelector>();
So far I haven't been able to express this in any simple way, but I'm still ramping up on Unity so I may have missed something.