0

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.

2
  • So you are looking for a way to inherit all controllers of your own base class, but without having to manually change this? Commented Mar 10, 2013 at 11:44
  • Yes, correct, thank you for clearing the question. Commented Mar 10, 2013 at 11:45

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Nice. I was thinking about using T4 templates, but didn't know Visual Studio already used T4 for generating the controllers.
@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 :)
actually you can inherit these Templates in your solution here hanselman.com/blog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.