开发者

How to extract component from WindsorContainer by key/id only

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 开发者_StackOverflowmatch 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜