ResolveAll via Dependency?

Jan 20, 2009 at 4:53 PM
Being new to Unity, I'm pretty sure the lack of documentation about this means I'm just thinking about it wrong.  I want to provide a few objects that share the same interface; whenever code needs to access that interface it can call ResolveAll and iterate through them, calling the same function on each, stopping early if it finds a satisfactory result.  So I figure I want a client class to receive the results of ResolveAll(T) rather than merely Resolve(T).  Is this possible with mere dependency injection?  Or does my client class need to have its own reference to IUnityContainer so it can call ResolveAll on its own?

An alternative is to create a container object that implements this interface by iterating and calling through its own collection of service objects.  Then I just register the container and it becomes easily accessible via dependency injection.  I'd like to know, though, whether ResolveAll can be called by dependency injection...
Jan 20, 2009 at 6:20 PM
Support for this was added in Unity 1.2.

All you need to do is have a property or parameter of type T[] (array of T). At resolve time, the container will internally call ResolveAll<T> and give you the resulting array (which may be empty). Also, be aware that ResolveAll deliberately does not return the unnamed registration for T, so you'll need to name all your registrations if you want them to show up when you do this.