ASP.NET MVC Controller. What have you done?
Here I am trying to follow the SOLID principles and create millions of tiny (microscopic even) classes and you come along with your 1 huge class that has a method for every single view I need. How dare you!!
In all seriousness – the controller makes it a bit harder to follow the SOLID principles (as well as other design patterns). In addition, if you want to create a class to get information that you will regularly need – you must call that class each time, which just gets a bit monotonous (even if it is static).
Solution? – Use a Base Class!
If you open one of your Controllers (Home.cs) you will see that it inherits System.Web.Mvc.Controller. This is what allows us to use properties like RouteData and HttpContextBase or methods like View() and PartialView(). (For a more complete list of what properties/methods the Controller class gives us see this link).
Now lets assume you have some property that is very important to your company – but doesn’t mean jack to anyone else. For example you sell one length of shoestrings – 76 inches. Let’s say you want a ShoeStringLength property in ALL of your controllers, and you don’t want to reference some static class each time. You could create a new Controller called BaseController (with the ShoeStringLength property), have that Controller inherit the System.Web.Mvc.Controller class (so that you have all of your MVC functionality available) and then have your Home Controller inherit your new BaseController class.
Using your own BaseController class will allow you to add properties and methods available in every Controller in your ASP.NET MVC app in a straightforward way!