I am getting
InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.SignInManager 1[Authorization.IdentityModels.ApplicationUser]' has been registered.
when I run my ApsCore MVC website.
this are segments from my code:
ConfigureServices:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole<Guid>>()
.AddEntityFrameworkStores<ApplicationDbContext, Guid>()
.AddDefaultTokenProviders();
Configure:
app.UseIdentity();
ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>
ApplicationUser.cs
public class ApplicationUser : IdentityUser<Guid>
I will be very happy if you can help me.
Faced with the same issue after moving my Identity classes to Guid and found solution here:
You probably need to change your login partial view to use the new user type IdentityUser
Within Views/Shared/_LoginPartial.cshtml
, I just changed
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
To
@using Microsoft.AspNetCore.Identity
@inject SignInManager<MyUser> SignInManager
@inject UserManager<MyUser> UserManager
and that worked for me.
Not sure if you are still seeing this issue, but here's some help for anyone else that stumbles upon this. (Note that the specifics are for version 1, but the need for an injected dependency not being available is the same.)
The issue is coming from some class in your application requiring a SignInManager in its constructor, but there isn't an implementation associated with it in the dependency injection setup.
To fix, in your Startup class, in the ConfigureServices method, register the SignInManager class in the services. For example:
services.AddScoped<SignInManager<ApplicationUser>, SignInManager<ApplicationUser>>();
The AddIdentity extension method may have been updated since the original question was asked to add this in, but the same error type will show up for anything the IoC container can't resolve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With