title: How to register custom UserManager, etc in DI - ASP.NET Core 2.1
body: <p>I need to create my own classes to handle identity in EF Core 2.1. I have the following ones, but when wanting to inbocar a method of a controller I get the following error </p>
  
  <p><strong>Unable to solve service for type 'Sample.API.Models.Identity.Stores.ApplicationUserStore' while attempting to activate 'Sample.API.Models .Identity.Managers.ApplicationUserManager'.</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection servicesCollection)
  {
      servicesCollection.AddDbContext&lt;MyIndentityContext&gt;(currentOptions =&gt;
          currentOptions.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
      servicesCollection.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;()
          .AddEntityFrameworkStores&lt;MyIndentityContext&gt;()
          .AddRoleStore&lt;ApplicationRoleStore&gt;()
          .AddUserStore&lt;ApplicationUserStore&gt;()
          .AddUserManager&lt;ApplicationUserManager&gt;()
          .AddRoleManager&lt;ApplicationRoleManager&gt;()
          .AddSignInManager&lt;ApplicationSignInManager&gt;()
          .AddDefaultTokenProviders();
  
          servicesCollection.AddTransient&lt;UserManager&lt;ApplicationUser&gt;, ApplicationUserManager&gt;();
          servicesCollection.AddTransient&lt;SignInManager&lt;ApplicationUser&gt;, ApplicationSignInManager&gt;();
          servicesCollection.AddTransient&lt;RoleManager&lt;ApplicationRole&gt;, ApplicationRoleManager&gt;();
          servicesCollection.AddTransient&lt;IUserStore&lt;ApplicationUser&gt;, ApplicationUserStore&gt;();
          servicesCollection.AddTransient&lt;IRoleStore&lt;ApplicationRole&gt;, ApplicationRoleStore&gt;();
  
          ...
  
          ...
  
          ...
  }
  
  public class MyIndentityContext : IdentityDbContext&lt;ApplicationUser, ApplicationRole, string&gt;
  {
      private readonly IConfiguration _configuration;
  
      private readonly IHttpContextAccessor _httpContextAccessor;
  
      public MyIndentityContext(DbContextOptions dbContextOptions, IHttpContextAccessor httpContextAccessor,
          IConfiguration configuration)
          : base(dbContextOptions)
      {
          _configuration = configuration;
          _httpContextAccessor = httpContextAccessor;
      }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          modelBuilder.HasDefaultSchema("Sample.API");
      }
  
  }
  
  public class ApplicationRoleManager : RoleManager&lt;ApplicationRole&gt;
  {
      public ApplicationRoleManager(ApplicationRoleStore roleStore,
          IEnumerable&lt;IRoleValidator&lt;ApplicationRole&gt;&gt; roleValidators, ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors, ILogger&lt;ApplicationRoleManager&gt; logger) : base(roleStore,
          roleValidators,
          keyNormalizer, errors, logger)
      {
      }
  }
  
  public class ApplicationSignInManager : SignInManager&lt;ApplicationUser&gt;
  {
      public ApplicationSignInManager(ApplicationUserManager userManager, IHttpContextAccessor contextAccessor,
          IUserClaimsPrincipalFactory&lt;ApplicationUser&gt; claimsFactory, IOptions&lt;IdentityOptions&gt; optionsAccessor,
          ILogger&lt;ApplicationSignInManager&gt; logger, IAuthenticationSchemeProvider schemes) : base(userManager,
          contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
      {
      }
  }
  
  public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(ApplicationUserStore userStore, 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, IServiceProvider services, ILogger&lt;ApplicationUserManager&gt; logger) :
          base(userStore, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors,
              services, logger)
      {
      }
  }
  
  public class ApplicationRoleStore : RoleStore&lt;ApplicationRole, MyIndentityContext&gt;
  {
      public ApplicationRoleStore(MyIndentityContext dbContext, IdentityErrorDescriber identityErrorDescriber)
          : base(dbContext, identityErrorDescriber)
      {}
  }
  
  public class ApplicationUserStore : UserStore&lt;ApplicationUser, ApplicationRole, MyIndentityContext, string&gt;
  {
      public ApplicationUserStore(MyIndentityContext dbContext, IdentityErrorDescriber identityErrorDescriber)
          : base(dbContext, identityErrorDescriber)
      {}
  
  }
  
  public class ApplicationUser : IdentityUser {}
  
  public class ApplicationRole : IdentityRole
  {
      public ApplicationRole() { }
  
      public ApplicationRole(string roleName) : base(roleName) { }
  
      public ApplicationRole(string roleName, string roleDescription) : base(roleName)
      {
          Description = roleDescription;
      }
  
  }
  
  [Authorize]
  [ApiController]
  [Route("api/[controller]")]
  [EnableCors(CORS.AllowSpecificOrigins)]
  
  public class UserController : BaseController
  {
      private readonly ApplicationUserManager _applicationUserManager;
  
      public UserController(ApplicationUserManager applicationUserManager)
      {
          _applicationUserManager = applicationUserManager;
      }
  
       // GET: api/User/5
      [HttpGet("{id}")]
      public async Task&lt;UserDTO&gt; Get(int id)
      {
  
          var currentuser = await _applicationUserManager.FindByNameAsync("NAME");
  
          return ...;
  
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After doing what the user "Camilo Terevinto" recommended, I made it work, but I also had to change the constructor of all the managers. For example I had to change <strong>ApplicationRoleStore roleStore</strong> by <strong>IRoleStore roleStore</strong></p>