views:

370

answers:

3

Hi guys Just a quick one.

In IOC's what does ResolveAll do?? I know that the offical answer is "Resolve all valid components that match this type." but does that mean that it will return any class that implements a given interface?

Cheers Anthony

+1  A: 

It will return all classes that were registered for a given interface.

Andrey Shchekin
+4  A: 

It will return all classes that were registered for a given interface.

...and are not waiting on any references to be resolved. This bit me today!

Chris Bilson
+1 for the important condition :)
Igor Brejc
Not **precisely** true. It will return components registered with given service and any other assignable service. So if you ask for `container.ResolveAll<IController>();` it will also return services registered as `IControllerWithCache`
Krzysztof Koźmic
Also the condition you mentioned is changed in v2.5. In v2.5 Windsor will try to resolve components that are waiting for dependencies (if the dependencies are provided inline, or via say `DynamicParameters`). Only if that attempt fails it will ignore the component and move to the next one.
Krzysztof Koźmic
Thanks Krzysztof!
Chris Bilson
A: 

With Unity, ResolveAll resolves each registered mapping for an interface except for the default mapping.

so if you registered:

container.RegisterType<IInterface, ActualClassOne>(new ContainerControlledLifetimeManager());
container.RegisterType<IInterface, ActualClassOne>("Singleton", new ContainerControlledLifetimeManager());
container.RegisterType<IInterface, ActualClassOne>("Trans", new TransientLifetimeManager());

ResolveAll() will only give you an IEnumerable containing a resolved "Singleton" and "Trans" mappings

LukeN
Why the hell does it do that? This has always annoyed me. #Unity #Fail
RhysC
Subtle encouragement not to use an unnamed mapping?
LukeN