简体   繁体   English

.Net Core 2.1自定义IdentityUI的依赖项注入失败

[英]Dependency injection fails for .Net Core 2.1 customized IdentityUI

The new .Net Core 2.1 Identity is very confusing. 新的.Net Core 2.1身份非常令人困惑。

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. InvalidOperationException:没有注册类型为'Microsoft.AspNetCore.Identity.UserManager`1 [Microsoft.AspNetCore.Identity.IdentityUser]'的服务。

What I'm doing wrong? 我做错了什么?

User has been registered with Identity Framework as the extended user identity model. User已向Identity Framework注册为扩展的用户身份模型。

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. 但是,异常消息表示项目中某处具有依赖于UserManager<IdentityUser>的类,该类将是模板中的默认类。

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> 由于扩展了默认值,因此UserManager<IdentityUser>引用默认值的UserManager<IdentityUser>都需要更新为UserManager<User>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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