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
精彩评论