As Scott pointed out in his post, there is now an “Add Controller…” option:
that will pull a template, called Controller.tt, from within:
Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC\CodeTemplates\AddController
and generate a controller for you based on that template.
The cool thing is that you can customize that template based on your desire to generate more than just the stub of a controller that it does out of the box. You can add all kinds of code in there based on your coding conventions that includes validation, logging, databinding, etc. This is extremely cool and I have been creating a custom Controller T4 Template that embodies my development style.
There are a couple of limitations that I have noticed, however:
Only 1 Controller Template – Unless I am missing something, you can’t choose a particular controller template like you can with a view template. This isn’t a deal breaker and maybe not even a big deal when I actually start using the template in development, but it seems like it would have been nice to be able to choose the controller template from a list of available templates in the folder just like one can with a view.
Only works with default Controllers Folder – It appears that the “Add Controller…” option only works when you are on the Controllers Folder that is generated by the MVC Project Wizard. I have a custom project that uses “Areas” and the “Add Controller…” option will not display when I choose my own custom folders for adding a controller.
If any of the above is possible, please let me know.
In general, however, I think the addition of using T4 Templates in the ASP.NET MVC Framework to generate controllers and views was a brilliant idea. Kudos to the MVC Team for adding it.