title: Asp.Net Identity Usermanager and Unit Of Work - how to mate them?
body: <p>I am using the Unit Of Work Pattern and have defined a class for it in a separate sub-project called MyProject.Domain.DAL.UnitOfWork.</p>
  
  <p>Unfortunately, the whole ASP.Net Identity infrastructure is in my main project (as in the tutorial), MyProject.</p>
  
  <p>Even more problematic: As I understand it, the ASP.NET identity uses it's own DBContext:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      /// &lt;summary&gt;
      /// Initializes a new instance of the &lt;see cref="ApplicationDbContext"/&gt; class, using the EFDB context.
      /// &lt;/summary&gt;
      public ApplicationDbContext()
          : base("EFDBContext", throwIfV1Schema: false)
      {
      }
  
      /// &lt;summary&gt;
      /// Creates this instance.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;A database context&lt;/returns&gt;
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>
  
  <p>I have a class called Project, which should have a user associated with it - but how to do that, without using conflicting db contexts?</p>
  
  <p>Example:</p>
  
  <pre><code>public class Project
  {
     public ApplicationUser User {get; set;}
  }
  </code></pre>
  
  <p>Example calling code:</p>
  
  <pre><code>public class IndexController : Controller
  {
      // uow and userManager are instantiated through Ninject
      // example code, normally this would be properties of the controller
      public ActionResult Create(IUnitOfWork uow, ApplicationUserManager userManager, int someID )
      {
         Project newProject = new Project(); 
         ApplicationUser user = await UserManager.FindByIdAsync(someID);
         // this should give a conflict, since two different DataContexts are involved
         newProject.User = user;
         uow.Projects.Insert(newProject);
         uow.Save()
         return this.View();
      }
  }
  </code></pre>
  
  <p>}</p>