title: How to register custom UserStore & UserManager in DI
body: <p>Here is my setup:</p>
  
  <pre><code>public class ApplicationUser : IdentityUser&lt;Guid&gt;
  {
  }
  public class ApplicationRole : IdentityRole&lt;Guid&gt;
  {
  }
  public class ApplicationUserLogin : IdentityUserLogin&lt;Guid&gt;
  {
  }
  public class ApplicationUserClaim : IdentityUserClaim&lt;Guid&gt;
  {
  }
  public class ApplicationRoleClaim : IdentityRoleClaim&lt;Guid&gt;
  {
  }
  </code></pre>
  
  <p>Here is the definition of my UserStore</p>
  
  <pre><code>public class ApplicationUserStore : UserStore&lt;ApplicationUser, ApplicationRole, MyContext, Guid&gt;
  {
      public ApplicationUserStore(MyContext context, IdentityErrorDescriber describer = null)
          : base(context, describer)
      {
      }
  }
  </code></pre>
  
  <p>Here is the definition of my UserManager</p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store, IOptions&lt;IdentityOptions&gt; optionsAccessor,
          IPasswordHasher&lt;ApplicationUser&gt; passwordHasher, IEnumerable&lt;IUserValidator&lt;ApplicationUser&gt;&gt; userValidators,
          IEnumerable&lt;IPasswordValidator&lt;ApplicationUser&gt;&gt; passwordValidators, ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors, IEnumerable&lt;IUserTokenProvider&lt;ApplicationUser&gt;&gt; tokenProviders,
          ILoggerFactory logger, IHttpContextAccessor contextAccessor)
          : base(
              store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors,
              tokenProviders, logger, contextAccessor)
      {
      }
  }
  </code></pre>
  
  <p>Here is the definition of my DbContext:</p>
  
  <pre><code>public class MyContext : IdentityDbContext&lt;ApplicationUser, ApplicationRole, Guid&gt;
  {
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
      }
  }
  </code></pre>
  
  <p>And here is my Startup.cs</p>
  
  <pre><code>    public IServiceProvider ConfigureServices(IServiceCollection services)
      {
          services.AddMvc();
  
          services.AddEntityFramework()
              .AddSqlServer()
              .AddDbContext&lt;MyContext&gt;(options =&gt; options.UseSqlServer(Configuration.Get("Data:DbConnection")));
  
          services.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;()
              .AddEntityFrameworkStores&lt;MyContext, Guid&gt;()
              .AddUserStore&lt;ApplicationUserStore&gt;()
              .AddRoleStore&lt;ApplicationRoleStore&gt;()
              .AddUserManager&lt;ApplicationUserManager&gt;()
              .AddRoleManager&lt;ApplicationRoleManager&gt;()
              .AddDefaultTokenProviders();
  
          var builder = new ContainerBuilder();
          builder.Populate(services);
          var container = builder.Build();
          return container.Resolve&lt;IServiceProvider&gt;();
      }
  </code></pre>
  
  <p>The dependency of this constructor will work:</p>
  
  <pre><code>public AccountController(UserManager&lt;ApplicationUser&gt; userManager, SignInManager&lt;ApplicationUser&gt; signInManager)
  </code></pre>
  
  <p>This one won't:</p>
  
  <pre><code>public AccountController(ApplicationUserManager userManager, SignInManager&lt;ApplicationUser&gt; signInManager)
  </code></pre>
  
  <p>Anyone has an idea on what I'm doing wrong?</p>