Home > other >  Error:Unable to resolve service for type 'Arad.ChatBot.Services.Services.IdentityModules.Applic
Error:Unable to resolve service for type 'Arad.ChatBot.Services.Services.IdentityModules.Applic

Time:08-03

I have a acoountController

[ApiController]
[Route("api/[controller]")]
public class AccountController
{
    private readonly IApplicationUserManager _userManager;
    private readonly IApplicationRoleManager _roleManager;
    private readonly SignInManager<ApplicationUser> _signInManager;

    public AccountController
        (IApplicationUserManager userManager, IApplicationRoleManager roleManager,
        SignInManager<ApplicationUser> signInManager)
    {
        _userManager = userManager;
        _roleManager = roleManager;
        _signInManager = signInManager;
    }

and config services in program.cs file

var connectionString = builder.Configuration.GetConnectionString("ChatBotConnection");
builder.Services.AddDbContext<ChatBotDbContext>(options => options.UseSqlServer(connectionString,
                sqlServerOptionsAction: sqlOption =>
                {
                    sqlOption.EnableRetryOnFailure();
                })
            );

 builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddUserManager<ApplicationUserManager>()
            .AddRoleManager<ApplicationRoleManager>()
            .AddUserStore<UserStore<ApplicationUser, ApplicationRole, ChatBotDbContext, string, IdentityUserClaim<string>, ApplicationUserRole, IdentityUserLogin<string>, IdentityUserToken<string>, IdentityRoleClaim<string>>>()
            .AddRoleStore<RoleStore<ApplicationRole, ChatBotDbContext, string, ApplicationUserRole, IdentityRoleClaim<string>>>()
            .AddSignInManager<SignInManager<ApplicationUser>>()
            .AddEntityFrameworkStores<ChatBotDbContext>()
            .AddDefaultTokenProviders();

i dont have error and show login page when i use postman i get error

System.InvalidOperationException: Unable to resolve service for type 'Arad.ChatBot.Services.Services.IdentityModules.ApplicationUserManager.IApplicationUserManager' while attempting to activate 'Arad.ChatBot.UI.Controllers.AccountController'.

CodePudding user response:

Change Code

 [ApiController]
  [Route("api/[controller]")]
public class AccountController
{
   private readonly UserManager<ApplicationUser> _userManager;
   private readonly RoleManager<ApplicationRole> _roleManager;
   private readonly SignInManager<ApplicationUser> _signInManager;

    public AccountController
    ( UserManager<ApplicationUser> userManager, RoleManager<ApplicationRole> roleManager,
    SignInManager<ApplicationUser> signInManager)
{
    _userManager = userManager;
    _roleManager = roleManager;
    _signInManager = signInManager;
}
  • Related