title: How to inject dependencies into the global.asax.cs
body: <p>How do I inject dependencies into the global.asax.cs, i.e. the MvcApplication class?</p>
  
  <p>Having previously used the Service Locator (anti-)pattern for dependency injection, I am trying to follow best practice advice in my latest MVC application by using an IOC container (specifically Unity.Mvc3 because it comes with an implementation of the IDependencyResolver out of the box) and constructor injection.  </p>
  
  <p>Everything seems quite straight forward so far except for a couple of snags, one of which is in the global.asax.cs (the other is for custom attributes but there's aleady a question on SO covering that).  </p>
  
  <p>The HttpApplication event handlers in the MvcApplication class such as:</p>
  
  <pre><code>Application_Start()
  Application_EndRequest(object sender, EventArgs e)
  Application_AcquireRequestState(object sender, EventArgs e)
  </code></pre>
  
  <p>may require external dependencies, e.g. a dependency on an ILogService.  So how do I inject them without resorting to the service locator (anti-)pattern of e.g.</p>
  
  <pre><code>private static ILogService LogService
  {
      get
      {
          return DependencyResolver.Current.GetService&lt;ILogService&gt;();
      }
  }
  </code></pre>
  
  <p>Any help/advice greatly appreciated!</p>