开发者

DependencyResolver vs. ControllerFactory

ASP.NET MVC 3 introduced DependencyResolver and I saw a lot of articles how cool it is. But wait... what is the difference comparing to ControllerFactory approach? Looks pretty simila开发者_开发百科r for me.


The ServiceLocator is designed as a layer of abstraction that will allow you to implement your own ServiceLocator Adapter which determines how services are resolved within your applications. One such example is the Windsor Service Locator Adapter.

The service locator has the ability to resolve controllers registered with the service locator according to Brad Wilson:

This is a new feature for MVC 3. The MVC framework (specifically, the DefaultControllerFactory class) has been updated to attempt to create all controller instances with the registered service locator.

The service locator can also be used throughout the framework to resolve a lot of other dependencies that the ASP.NET MVC framework uses like dependencies required by ActionFilters, ResultHandlers and even ViewEngines.

If you make all your instances of your controllers available, for a standard app, it's highly unlikely that you would need a custom controller factory.

However, if you need to do something specific before, during or after the instantiation of your controller, you can use the controllerfactory to take care of these specific implementations before it is returned for use by the rest of the framework.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜