开发者

ASP.NET MVC BaseController

开发者 https://www.devze.com 2023-01-06 01:02 出处:网络
I use a BaseController to wire up my service layer. All other controllers inherit this controller. Now I\'m embarking on building an MVC2 project templ开发者_如何转开发ate. I would like controllers to

I use a BaseController to wire up my service layer. All other controllers inherit this controller. Now I'm embarking on building an MVC2 project templ开发者_如何转开发ate. I would like controllers to inherit this by default, not just the ": Controller", but have no idea how to approach this.


You can use custom t4 templates to do this

http://www.davidhayden.me/2009/11/aspnet-mvc-and-t4-templates-generating-controllers-and-views.html


I'd note that if it is just to wire in a service layer, you might well be better served by using an IoC container (eg--structuremap) and dependency injection into otherwise unadulterated Controllers. Or, Composition > Inheritance any day.

0

精彩评论

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