Resolving IEnumerable<T> with Unity
Posted
by Mark Seemann
on Stack Overflow
See other posts from Stack Overflow
or by Mark Seemann
Published on 2009-12-25T17:26:33Z
Indexed on
2010/05/13
22:14 UTC
Read the original article
Hit count: 693
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.
© Stack Overflow or respective owner