简体   繁体   中英

How to add custom TUser and TRole into services.AddIdentity in ASP.NET Core?

I have error in next code in

public void ConfigureServices(IServiceCollection services)

    services.AddIdentity<ApsUser, ApsRole>(option =>
        {
            option.Password.RequiredLength = 6;
        })

GenericArguments[0], 'project.Core.Users.ApsUser', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]' violates the constraint of type parameter 'TUser'.

My class

public class ApsUser : IdentityUser<int, UserClaim, UserRole, UserLogin>, IEntity
{
    public UserState State { get; set; }

    #region IEntityLogFields



    #endregion

}

public class UserRole : IdentityUserRole<int>, IEntity<int>
{
    public int Id { get; set; }

    #region IEntityLogFields



    #endregion

}

How to fix the error?

Temporary i made this

  1. user and role

    public class ApsUser : IdentityUser<int>, IEntity

    public class ApsRole : IdentityRole, IEntityLog

  2. startup.cs

    services.AddIdentity(option => { option.Password.RequiredLength = 6; option.Password.RequireLowercase = false; option.Password.RequireNonAlphanumeric = false; option.Password.RequireUppercase = false; option.Password.RequireNonAlphanumeric = false;

      }) .AddEntityFrameworkStores<ApContext, int>() .AddDefaultTokenProviders(); 

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