Search code examples
asp.net-mvccode-organization

Why are the controllers on ASP.NET MVC name-based?


In ASP.NET MVC, we're required to use the suffix "Controller" for all controllers. This seems unnecessarily restrictive - is there a technical reason for it?

I'm mostly just curious, but can see situations where more flexible naming rules could improve code organization. Couldn't the discovery of possible controller classes be easily made using reflection to search for Controller derived classes? Or require that controller classes be marked with a ControllerAttribute?


Solution

  • The MVC community is heavily influenced by Ruby on Rails, which values "convention over configuration". By just naming things consistently, the application can run with zero configuration.