Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are no good uses of a base controller class. </p> <p>Now hear me out.</p> <p>Asp.Net MVC, especially MVC 3 has tons of extensibility hooks that provide a more decoupled way to add functionality to all controllers. Since your controllers classes are very important and central to an application its really important to keep them light, agile and loosely coupled to everything else.</p> <ul> <li><p>Logging infrastructure belongs in a constructor and should be injected via a DI framework.</p></li> <li><p>CRUD scaffolding should be handled by code generation or a custom ModelMetadata provider.</p></li> <li><p>Global exception handling should be handled by an custom ActionInvoker.</p></li> <li><p>Global view data and authorization should be handled by action filters. Even easier with Global action filters in MVC3.</p></li> <li><p>Constants can go in another class/file called ApplicationConstants or something.</p></li> </ul> <p>Base Controllers are usually used by inexperienced MVC devs who don't know all the different extensibility pieces of MVC. Now don't get me wrong, I'm not judging and work with people who use them for all the wrong reasons. Its just experience that provides you with more tools to solve common problems.</p> <p>I'm almost positive there isn't a single problem you can't solve with another extensibility hook than a base controller class. Don't take on the the tightest form of coupling ( inheritance ) unless there is a significant productivity reason and you don't violate Liskov. I'd much rather take the &lt; 1 second to type out a property 20 times across my controllers like <code>public ILogger Logger { get; set; }</code> than introduce a tight coupling which affects the application in much more significant ways.</p> <p>Even something like a userId or a multitenant key can go in a ControllerFactory instead of a base controller. The coupling cost of a base controller class is just not worth it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload