title: When base controller is initialized in MVC
body: <p>I am working on a web application in MVC 2 that employs a base controller for all other controllers to reduce initialization of controllers to one place. The base controller contains properties like menu, current user etc. Here is the code:</p>
  
  <pre><code>public class BaseController : Controller 
  {
      private Common.MenuHierarchy _menu;
      private User _currentUser;
  
      internal NavMenuViewModel Menu(string pageId)
      {
          bool isGuest = this.CurrentUser.GroupProfileId == Constant.SecurityGroupProfile.Public;
  
          if (this._menu == null)
          {
              this._menu = CreateMenu();
          }
      }
  
      internal User CurrentUser
      {
          get
          {
              if (this._currentUser == null)
              {
                  this._currentUser = CreateUser();
              }
  
              return this._currentUser;
          }
      }
  }
  </code></pre>
  
  <p>All other controller derive from BaseController. For example,</p>
  
  <pre><code>public class HomeController : BaseController
  {
     ...
  }
  
  public ActionResult Index()
  {
     // Display home page
     ...
  }
  </code></pre>
  
  <p>I notice that after directed to Home index, the _currentUser property has been initialized. But if I set point break inside get, it won't stop there. I wonder when base controller is initialized. Thanks.</p>