开发者

What is the correct way of Instantiate Controller with IoC

I am migrating to ASP.NET MVC 3.

Now I have some way开发者_JAVA技巧s of resolve controller with IoC.

My controller need a contructor injection parameter for repositories.

Setting DependencyResolver.SetResolver works. But I don´t know if this is correct way or I need to Register a IControllerActivator at my container too.


What you need is a ControllerFactory.Most IOC containers have an existing implementation. If you need a custom one, check this article:

http://develoq.net/blog/?p=144

Update

It's the correct way. DependencyResolver is generic for everything, and you need to register the IControllerActivator in it.

http://bradwilson.typepad.com/blog/2010/10/service-location-pt10-controller-activator.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜