How to extract component from WindsorContainer by key/id only

744 Views Asked by At

In version 1.3 you can use contaier[cmpKey] to extract a component with all dependency if any. into new release (2.5) that accessor is obsolete and none of the options provided by Resolve Method really match with old one. I might figure out Type by key/id, but I wonder if there's still a supported why to extract a cmp by key/id only

2

There are 2 best solutions below

0
On BEST ANSWER

Actually better option than what Mauricio suggested (although there's nothing wrong with his solution except the object argument is a bit confusing) is

var instance = container.Resolve<object>("component-name");

In Windsor when key is provided it has the priority and components are looked up by the key solely. The type is used only as a syntactic sugar to avoid casting.

0
On
object component = container.Resolve("component-name", new object());

I'd still recommend using the strongly-typed Resolve<T> instead, unless there really is no choice.