title: Resolving dbcontext per request with Unity in WebApi
body: <p>I am struggling to make this work. I've got Unity and Unity.AspNet.WebApi packages (v 3.5.1404) installed and below activation code which came with the packages</p>
  
  <pre><code>public static class UnityWebApiActivator
  {
      /// &lt;summary&gt;Integrates Unity when the application starts.&lt;/summary&gt;
      public static void Start() 
      {
          var container = UnityConfig.GetConfiguredContainer();
          var resolver = new UnityHierarchicalDependencyResolver(container);
  
          GlobalConfiguration.Configuration.DependencyResolver = resolver;
  
          // DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
      }
  
      /// &lt;summary&gt;Disposes the Unity container when the application is shut down.&lt;/summary&gt;
      public static void Shutdown()
      {
          var container = UnityConfig.GetConfiguredContainer();
          container.Dispose();
      }
  }
  </code></pre>
  
  <p>and my type registration looks like this:</p>
  
  <pre><code> public static void RegisterTypes(IUnityContainer container)
          {
              container.RegisterType&lt;IAuditService, AuditService&gt;(
                  new PerThreadLifetimeManager(),
                  new InjectionConstructor(new SecurityDbContext()));
          }
  </code></pre>
  
  <p>So far I've tried PerThreadLifetimeManager and TransientLifetimeManager with no success. I've also got the Unity.Mvc package and tried using the PerRequestLifetimeManager as suggested by msdn but no luck. It always gives me the same instance of dbcontex.</p>
  
  <p>I rather do not include any MVC dependency as this is purely WebApi but when I try to use Unity.Mvc, I ended up some http runtime errors too.</p>
  
  <p>Anyone has a good suggestion/example to resolve dbcontext per request with Unity in WebApi, preferably without any mvc dependency?</p>