开发者

Retrieve an object from Unity IoC container

When I worked in Spring, I could get a bean a bean listed in my applicationContext. This object would already be populated with all the values that were there when 开发者_运维技巧the bean was instantiated. Great.

I can't find a way to do this in Microsoft Unity IoC. We recently introduced this framework into our codebase and nobody is really very familiar with it yet. The only examples I've seen involve resolving the type of the object and then repopulating all the values. Yuck. I don't want to do this.

I want to pull the object from the container and it should be ready to go. Does anyone know how to do this?


Is a call to Resolve not enough, e.g.

var container = // create container.
IService instance = container.Resolve<IService>();

Unity will inject any dependencies before returning the resolves instance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜