title: Ninject-ing a dependency in Global.asax
body: <p>I'm starting a web application with MVC3 and Ninject. There is one dependency that I also need in the Global.asax file that needs to be a singleton.</p>
  
  <p>I thought it should be like this:</p>
  
  <pre><code>public class MvcApplication : NinjectHttpApplication
  {
      IUserAuthentication _auth;
  
      public MvcApplication()
      {
          base.AuthenticateRequest += new EventHandler(MvcApplication_AuthenticateRequest);
      }
  
      protected override IKernel CreateKernel()
      {
          var _kernel = new StandardKernel(new SecurityModule());
          _auth = _kernel.Get&lt;IUserAuthentication&gt;();
  
          return _kernel;
      }
  
      void MvcApplication_AuthenticateRequest(object sender, EventArgs e)
      {
          _auth.ToString();
      }
  </code></pre>
  
  <p>But then I saw that <code>_auth</code> is null when <code>MvcApplication_AuthenticateRequest</code> is called.</p>
  
  <p>Then I tried like this:</p>
  
  <pre><code>public class MvcApplication : NinjectHttpApplication
  {
      ItUserAuthentication _auth;
      IKernel _kernel;
  
      public MvcApplication()
      {
          _kernel = new StandardKernel(new SecurityModule());
          _auth = _kernel.Get&lt;IUserAuthentication&gt;();
          base.AuthenticateRequest += new EventHandler(MvcApplication_AuthenticateRequest);
      }
  
      protected override IKernel CreateKernel()
      {
          return _kernel;
      }
  
      void MvcApplication_AuthenticateRequest(object sender, EventArgs e)
      {
          _auth.ToString();
      }
  </code></pre>
  
  <p>But now I can see that the constructor is being called several times, therefore I will have several IKernel, and I guess that singleton instances won't be so singleton in my app scope.</p>
  
  <p>How should I do it? Using a static variable?</p>