简体   繁体   中英

Dependency injection fails for .Net Core 2.1 customized IdentityUI

The new .Net Core 2.1 Identity is very confusing.

Here is my code:

STARTUP.CS

services.AddIdentity<User, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
        .AddEntityFrameworkStores<ApplicationDbContext>() 
        .AddDefaultUI()
        .AddDefaultTokenProviders();

DBCONTEXT

public class ApplicationDbContext : IdentityDbContext<User>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }
}

But I got this error:

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.

What I'm doing wrong?

User has been registered with Identity Framework as the extended user identity model.

However, the exception message implies that somewhere in the project has a class dependent on UserManager<IdentityUser> , which would have been the default from the template.

Since the default has been extended, then where ever there is reference to the default UserManager<IdentityUser> would need to be updated to UserManager<User>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM