Whats ResolveAll do
Asked Answered
A

4

6

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

Annadiana answered 5/12, 2008 at 7:2 Comment(1)
What does IOC stand for in this context?Cecil
U
10

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!

Uniat answered 4/2, 2009 at 23:21 Comment(2)
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 IControllerWithCacheMindymine
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.Mindymine
G
2

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

Giselle answered 28/4, 2010 at 5:14 Comment(5)
Why the hell does it do that? This has always annoyed me. #Unity #FailBarracuda
Subtle encouragement not to use an unnamed mapping?Giselle
Ahem.. question was about Castle-Windsor :) Anyways, that's fairly important piece of information. Maybe consider cut&paste to some Unity-related question? I bet there's plentyRi
I'd rather steer people to windsor, ninject or something nice. I was stuck with prism and unityGiselle
The "except for the default mapping." part above is vitally important. Seems a flaw in Unity, but finding this has been a massive help!Orvie
F
1

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

Fountain answered 5/12, 2008 at 7:22 Comment(0)
J
0

If I have:

container.ResolveAll(new { argument = something}).Where(...)

it seems like all components of T gets instantiated with 'something' even though not all of the components full fill the where clause.... who takes care of Releasing these extra components?

Jaymejaymee answered 27/2, 2013 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.