In my ASP.NET MVC applications, all controller I create via Visual Studio UI are inherited from Controller class. I use my own version of a base controller class that I need all my controller to inherit from. Is there a mechanism that would allow me to bypass the manual rewriting of Controller inheritance and put my own BaseController automatically.
-
So you are looking for a way to inherit all controllers of your own base class, but without having to manually change this?Steven– Steven2013-03-10 11:44:25 +00:00Commented Mar 10, 2013 at 11:44
-
Yes, correct, thank you for clearing the question.Maxim V. Pavlov– Maxim V. Pavlov2013-03-10 11:45:14 +00:00Commented Mar 10, 2013 at 11:45
Add a comment
|
1 Answer
Depending on how your machine is setup you can browse to your VS installation and make a few changes.
On my machine the location is C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController
You can modify Controller.tt (a T4 template).
Make a backup of this file if you'll need to revert :)
Update!
Qpirate pointed me to a link in the comments below.
From Scott Hanselmans Blog This is an even easier way to create your own version without affecting the global ones.
3 Comments
Steven
Nice. I was thinking about using T4 templates, but didn't know Visual Studio already used T4 for generating the controllers.
scartag
@Steven Yeah they do .. what i need to find out is how to create my own project type .. so i can instantly add all my "cruft" i usually add when developing :)
Qpirate
actually you can inherit these Templates in your solution here hanselman.com/blog/…