title: Creating a UserManager outside of built in dependency injection system
body: <p>This is using asp.net core with identity and entity framework core.  I working on a saas application where I have a separate admin web app where you can add new tenants to the system.  After a tenant is creates the app creates a default database (database per tenant set up) for the new tenant.  I want to add a default user to this new database but I'm struggling with creating user manager outside of the dependency injection system.</p>
  
  <p>The admin web app uses the usermanager that is created in the startup.cs (via the built in DI system) as the manager for the admin app.  When I go to add the user to the new tenants database I am not using the DI system I just want to create a UserManager with the IdentityDbContext associated with the connection string for the new tenants database.</p>
  
  <p>I'm am using this after a new tenant is created in the admin app:</p>
  
  <pre><code>public class TenantDbInitializer
  {
      private Tenant tenant;
      private ApplicationDbContext context;
  
      private UserManager&lt;ApplicationUser&gt; userManager;
  
      public TenantDbInitializer(Tenant tenant)
      {
          this.tenant = tenant;
      }
  
      public void Init()
      {
          // tenant contains connection string
          context = new ApplicationDbContext(tenant); 
  
          var userStore = new UserStore&lt;ApplicationUser&gt;(context);
  
          userManager = new UserManager&lt;ApplicationUser&gt;(.........
      }
  }
  </code></pre>
  
  <p>The UserManager construction parameters contain items that I can't find examples on what instances I should use.  Some of the interfaces appear to have default implementations but I'm not sure if this is the way to proceed (or to pass null).  The constructor is:</p>
  
  <pre><code>    public UserManager(IUserStore&lt;TUser&gt; store,
          IOptions&lt;IdentityOptions&gt; optionsAccessor,
          IPasswordHasher&lt;TUser&gt; passwordHasher,
          IEnumerable&lt;IUserValidator&lt;TUser&gt;&gt; userValidators,
          IEnumerable&lt;IPasswordValidator&lt;TUser&gt;&gt; passwordValidators,
          ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors,
          IServiceProvider services,
          ILogger&lt;UserManager&lt;TUser&gt;&gt; logger)
  </code></pre>
  
  <p>Looking at the identity source it appears that I can pass null in for some of these parameters but I want to make sure I understand what is going on here so I don't do anything incorrectly.</p>
  
  <p>The source for user manager is here:
  <a href="https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNetCore.Identity/UserManager.cs" rel="noreferrer">https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNetCore.Identity/UserManager.cs</a></p>
  
  <p>Thanks,
  Brian</p>