Getting error InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'NostedServicePro.Controllers.BrukerController'.
BrukerController contructor (Bruker is the same as Account if that helps)
public class BrukerController : Controller
{
private readonly ServiceProDbContex _dbContext;
private readonly SignInManager<IdentityUser> _signInManager;
private readonly ILogger _logger;
private readonly UserManager<IdentityUser> _userManager;
private readonly IEmailSender _emailSender;
public BrukerController(
ServiceProDbContex dbContext,
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager,
ILoggerFactory loggerFactory,
IEmailSender emailSender)
{
_dbContext = dbContext;
_signInManager = signInManager;
_logger = loggerFactory.CreateLogger<BrukerController>();
_userManager = userManager;
_emailSender = emailSender;
}
ConfigureServices method in startup.cs:
public void ConfigureServices(IServiceCollection services)
{
// ...
// Configure the database context using the connection string from appsettings.json
services.AddDbContext<ServiceProDbContex>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), ServerVersion.AutoDetect(Configuration.GetConnectionString("DefaultConnection"))));
services.AddIdentity<NostedServicePro.Models.Bruker, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<ServiceProDbContex>()
.AddDefaultTokenProviders();
// ...
services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
}).AddIdentityCookies(options => { });
services.AddAuthorization();
}