I'm building a completely custom AspNetCore.Identity Implementation because I want TKey
to be System.Guid
across the board. With respect, I have derived types for...
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
is the problem child!
Implementation
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>
{
}
}
Error
The type 'NewCo.Identity.Role' cannot be used as type parameter 'TRole' in the generic type or method 'UserStore'. There is no implicit reference conversion from 'NewCo.Identity.Role' to 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole>'.
As far as I can see, unless this is some (co/contra/in)variance issue, all the code checks out...what did I get wrong?
Your
ApplicationUserStore
needs theRoleClaim
at the end too (don't forget to update the related NuGet packages, otherwise you can't use these new additions):Plus your
ApplicationRoleStore
should provide how to create theRoleClaim
,And also the
ApplicationUserStore
should provide these mappings too:Then redirect built-in services to your custom services:
now introduce your custom services: