Having been a part of many large enterprise ASP.NET MVC application implementations using test driven development I learned early on that separating your controller classes into a their own project significantly reduces the noise in your web project. It wasn’t until a recent talk I gave to user group in my region that I realized that this isn’t a widely adopted practice. For large applications with a lot of developers and a complex architecture I highly recommend it.
Putting your controllers in a separate assembly is very straight forward. First create a controllers project in your solution and then you just need to update your route registrations to tell them where to look for the controllers.
In order to tell ASP.NET MVC where to look for your controllers when registering your routes you use the ‘namespaces’ parameter of the MapRoute method as illustrated above.
I know that the concept of putting controllers in a separate assembly is a bit controversial and everyone seems to have a strong opinion either for or against, so let me know what side of the fence you fall on.
Keith is a Senior Software Engineer with Falafel Software. He has been developing software since 1999 specializing in web-based solutions primarily using the Microsoft stack. He has been a Microsoft MVP in ASP.NET since 2012.
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way.