我正在构建一个完全自定义的AspNetCore.Identity实现,因为我想要TKey
全部是System.Guid
。恕我直言,我已经派生类型...AspNetCore.Identity自定义实现不工作
Role : IdentityRole<Guid, UserRole, RoleClaim>
RoleClaim : IdentityRoleClaim<Guid>
User : IdentityUser<Guid, UserClaim, UserRole, UserLogin>
UserClaim : IdentityUserClaim<Guid>
UserLogin : IdentityUserLogin<Guid>
UserRole : IdentityUserRole<Guid>
UserToken : IdentityUserToken<Guid>
ApplicationDbContext : IdentityDbContext<User, Role, Guid, UserClaim, UserRole, UserLogin, RoleClaim, UserToken>
ApplicationRoleManager : RoleManager<Role>
ApplicationRoleStore : RoleStore<Role, ApplicationDbContext, Guid, UserRole, RoleClaim>
ApplicationSignInManager : SignInManager<User>
ApplicationUserManager : UserManager<User>
**ApplicationUserStore** : UserStore<User, Role, ApplicationDbContext, Guid, UserClaim, UserRole, UserLogin, UserToken>
ApplicationUserStore
是问题的孩子!
实施
namespace NewCo.Identity
{
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System;
public sealed class Role : IdentityRole<Guid, UserRole, RoleClaim>
{
}
}
namespace NewCo.Identity
{
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System;
public sealed class UserRole : IdentityUserRole<Guid>
{
}
}
namespace NewCo.Identity
{
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System;
public sealed class RoleClaim : IdentityRoleClaim<Guid>
{
}
}
// The problem is here...
namespace NewCo.Identity
{
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System;
using System.Security.Claims;
public sealed class ApplicationUserStore : UserStore<User, Role, ApplicationDbContext, Guid, UserClaim, UserRole, UserLogin, UserToken>
{
}
}
错误
类型 'NewCo.Identity.Role' 不能在通用类型或方法被用作类型参数 'TRole' 'UserStore'。 不是从'NewCo.Identity.Role'到 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole>'的隐式引用转换。
就我所见,除非这是一些(共同/对比/中)差异问题,否则所有代码都会检查出来......我错了什么?
这个问题问得好!约束条件是“TRole:IdentityRole>'。由于这是* class *约束,因此不存在共同/反对。 IMO他们只是忘了添加TRoleClaim泛型参数:( –
@IvanStoev谢谢,我已经提出这与ASPNETCore/Identity团队。 – series0ne
https://github.com/aspnet/Identity/issues/1319 – series0ne