title: Unity IoC Lifetime per HttpRequest for UserStore
body: <p>I'm trying to clean up the default implementation of AccountController.cs that comes out of the box in the new MVC5/Owin security implementation.   I have modified my constructor to look like this:</p>
  
  <pre><code>private UserManager&lt;ApplicationUser&gt; UserManager;
  public AccountController(UserManager&lt;ApplicationUser&gt; userManager)
  {
      this.UserManager = userManager;
  }
  </code></pre>
  
  <p>Also, I have created a lifetime manager for Unity that looks like this:</p>
  
  <pre><code> public class HttpContextLifetimeManager&lt;T&gt; : LifetimeManager, IDisposable
      {
          private HttpContextBase _context = null;
          public HttpContextLifetimeManager()
          {
              _context = new HttpContextWrapper(HttpContext.Current);
          }
          public HttpContextLifetimeManager(HttpContextBase context)
          {
              if (context == null)
                  throw new ArgumentNullException("context");
              _context = context;
          }
          public void Dispose()
          {
              this.RemoveValue();
          }
          public override object GetValue()
          {
              return _context.Items[typeof(T)];
          }
          public override void RemoveValue()
          {
              _context.Items.Remove(typeof(T));
          }
          public override void SetValue(object newValue)
          {
              _context.Items[typeof(T)] = newValue;
          }
      }
  </code></pre>
  
  <p>I'm not sure how to write this in my UnityConfig.cs, but this is what I have so far:</p>
  
  <pre><code>container.RegisterType&lt;UserManager&lt;ApplicationUser&gt;&gt;(new HttpContextLifetimeManager(new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(new RecipeManagerContext()))));
  </code></pre>
  
  <p>I did find another example (using AutoFac) that does it this way:</p>
  
  <pre><code>container.Register(c =&gt; new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;( new RecipeManagerContext())))
                  .As&lt;UserManager&lt;ApplicationUser&gt;&gt;().InstancePerHttpRequest();
  </code></pre>
  
  <p>How would I translate the above statement using Unity IoC lifetime management?</p>