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?
Whats ResolveAll do
Asked Answered
What does IOC stand for in this context? –
Cecil
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!
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
–
Mindymine 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 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
Why the hell does it do that? This has always annoyed me. #Unity #Fail –
Barracuda
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 plenty –
Ri
I'd rather steer people to windsor, ninject or something nice. I was stuck with prism and unity –
Giselle
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
It will return all classes that were registered for a given interface.
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?
© 2022 - 2024 — McMap. All rights reserved.