title: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager hile attempting to activate 'Controllers.AccountsController'
body: <p>I have the following code in the AccountsController :</p>
  
  <pre><code>using System.Threading.Tasks;
  using AutoMapper;
  using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Mvc;
  using Products.Helpers;
  using Products.Models;
  using Products.ViewModels;
  
  namespace Products.Controllers
  {
      [Route("api/[controller]")]
      [ApiController]
      public class AccountsController : Controller
      {
          private readonly ContextUsers _appDbContext;
          private readonly UserManager&lt;AppUser&gt; _userManager;
          private readonly IMapper _mapper;
  
      public AccountsController(ContextUsers context,UserManager&lt;AppUser&gt; userManager,IMapper mapper)
      {
          _appDbContext = context;
          _userManager = userManager;
          _mapper = mapper;
      }
  
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; Post([FromBody]RegistrationViewModel model)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          var userIdentity = _mapper.Map&lt;AppUser&gt;(model);
  
          var result = await _userManager.CreateAsync(userIdentity, model.Password);
  
          if (!result.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState));
  
          await _appDbContext.Customers.AddAsync(new Customer { IdentityId = userIdentity.Id, Location = model.Location });
          await _appDbContext.SaveChangesAsync();
          return new OkObjectResult("Account created");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And I have the following code in the AppUser class:</p>
  
  <pre><code>public class AppUser : IdentityUser
  {
    // Extended Properties
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public long? FacebookId { get; set; }
    public string PictureUrl { get; set; }
  }
  </code></pre>
  
  <p>And the following Customer class:</p>
  
  <pre><code>public class Customer
  {
   public int Id { get; set; }
   public string IdentityId { get; set; }
   public AppUser Identity { get; set; }  // navigation property
   public string Location { get; set; }
   public string Locale { get; set; }
   public string Gender { get; set; }
  }
  </code></pre>
  
  <p>When i make a post request in postman i get the following error:</p>
  
  <pre><code>InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Products.Models.AppUser]' while attempting to activate 'Products.Controllers.AccountsController'.
  Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
  </code></pre>
  
  <p>I am trying to create a user but when I make the post request doesn't even enter the controller so I can't debug</p>
  
  <p>ConfigureServices method from startup.cs:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
  
                  .AddCors(o =&gt; o.AddPolicy("AllowAllOrigins", builder =&gt;
              {
                  builder.AllowAnyMethod()
                      .AllowAnyHeader()
                      .AllowAnyOrigin();
              }));
  
              services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  
              services.AddDbContext&lt;Context&gt;(options =&gt;
                      options.UseSqlServer(Configuration.GetConnectionString("LaprDB")));
              services.AddDbContext&lt;ContextUsers&gt;(options =&gt;
                  options.UseSqlServer(Configuration.GetConnectionString("MyDbConnection")));
  
  
              services.AddHostedService&lt;TimedHostedService&gt;();
  
               services.AddAutoMapper();
  
  
          }
  </code></pre>