title: ASP.NET Identity 2.0. Lifetime managment of DbContext object
body: <p>Acoording to this article <a href="http://blogs.msdn.com/b/webdev/archive/2014/02/12/per-request-lifetime-management-for-usermanager-class-in-asp-net-identity.aspx" rel="nofollow">http://blogs.msdn.com/b/webdev/archive/2014/02/12/per-request-lifetime-management-for-usermanager-class-in-asp-net-identity.aspx</a> (default ASP.NET MVC 5 template implements this approach )   <strong>ApplicationUserManager</strong> object should be created once per request. It means,  that  <strong><em>ApplicationUserManager.Create(IdentityFactoryOptions options, IOwinContext context)</em></strong> method is called for every request. But this method  has this code:</p>
  
  <pre><code>   public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context) 
      {
          var manager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;(context.Get&lt;ApplicationDbContext&gt;()));
          ...
      }
  </code></pre>
  
  <p>This code means, that <strong>ApplicationDbContext</strong> object is also created per every request. Thats why, I have several questions.</p>
  
  <ol>
  <li>Is it normal to create new <strong>ApplicationDbContext</strong> object for every request?</li>
  <li>If it is not good practice to create <strong>ApplicationDbContext</strong> for every request, how can I avoid doing this?</li>
  <li>And in fact, can i replace DI containers with Owin and use <strong><em>CreatePerOwinContext</em></strong> and <strong><em>GetOwinContext().Get()</em></strong> methods? In fact, OWIN based approach can replace dependency injection for controllers, but I can not find lifetime managment in OWIN</li>
  <li>If I can not do this, how can I combine OWIN based ASP.NET Identity and DI containers? </li>
  </ol>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have forgotten to mention, that I plan to use MongoDb and mongosharp driver for storing data. Thay say, that I can keep one connection for all application</p>