title: Seed database for Identity 2
body: <p>I came across a problem for seeding the database with Identity v2. I separated out the IdentityModel from the MVC5 project to my Data Access Layer where I setup EF Migrations as well. So I commented out the code which use inside "IdentityConfig.cs" to create initial user and put the code inside my seed database that looks like this</p>
  
  <pre><code>  protected override void Seed(Repository.DataContext.IdentityDb context)
          {
  
              //    var userManager = HttpContext.Current.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
              //    var roleManager = HttpContext.Current.GetOwinContext().Get&lt;ApplicationRoleManager&gt;();
              var owinContext = new OwinContext();
              var userManager = owinContext.GetUserManager&lt;ApplicationUserManager&gt;();
              var roleManager = owinContext.Get&lt;ApplicationRoleManager&gt;();
              const string name = "admin@admin.com";
              const string password = "Admin@123456";
              const string roleName = "Admin";
  
              //    //Create Role Admin if it does not exist
              var role = roleManager.FindByName(roleName);
              if (role == null)
              {
                  role = new IdentityRole(roleName);
                  var roleresult = roleManager.Create(role);
              }
  
              var user = userManager.FindByName(name);
              if (user == null)
              {
                  user = new ApplicationUser { UserName = name, Email = name };
                  var result = userManager.Create(user, password);
                  result = userManager.SetLockoutEnabled(user.Id, false);
              }
  
              //    // Add user admin to Role Admin if not already added
              var rolesForUser = userManager.GetRoles(user.Id);
              if (!rolesForUser.Contains(role.Name))
              {
                  var result = userManager.AddToRole(user.Id, role.Name);
              }
          }  
  </code></pre>
  
  <p>Now when I am running command update-database, I got an error</p>
  
  <pre><code>Value cannot be null.
  Parameter name: manager
  </code></pre>
  
  <p>It looks like, I am getting null in these two lines of code</p>
  
  <pre><code>var userManager = owinContext.GetUserManager&lt;ApplicationUserManager&gt;();
  var roleManager = owinContext.Get&lt;ApplicationRoleManager&gt;();
  </code></pre>
  
  <p>Any suggestion please?</p>