开发者

What is the correct way of Instantiate Controller with IoC

开发者 https://www.devze.com 2023-02-04 00:45 出处:网络
I am migrating to ASP.NET MVC 3. Now I have some way开发者_JAVA技巧s of resolve 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

精彩评论

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