I'm trying to configure my authentication and authorization using my existing database and tables, without using Entity Framework (using Dapper).
I've got the Dapper configured correctly, now I'm trying to hook up the SignInManager, and UserManager to call my database via Dapper, but before that can happen, I'm running into some errors with my custom role store.
Here's the error that I'm receiving when I click the "Register" button on the website (this is just a plain project with all of the pre-defined account etc stuff out of the box)
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNet.Identity.IRoleStore`1[TestAsyncWebsite.Configuration.WrestleStatRole]' while attempting to activate 'Microsoft.AspNet.Identity.RoleManager`1[TestAsyncWebsite.Configuration.WrestleStatRole]'
For now, here's how I have configured my custom user, role, userstore, role store, usermanager, and rolemanager:
public class WrestleStatUser : ApplicationUser
{
public WrestleStatUser() : base()
{
}
}
public class WrestleStatRole : IdentityRole
{
}
public class WrestleStatUserStore : IUserStore<WrestleStatUser>
{
// all methods implemented
}
public class WrestleStatRoleStore : IRoleStore<WrestleStatRole>
{
// all methods implemented
}
public class WrestleStatUserManager : UserManager<WrestleStatUser>
{
public WrestleStatUserManager(IUserStore<WrestleStatUser> store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<WrestleStatUser> passwordHasher, IEnumerable<IUserValidator<WrestleStatUser>> userValidators, IEnumerable<IPasswordValidator<WrestleStatUser>> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IEnumerable<IUserTokenProvider<WrestleStatUser>> tokenProviders, ILogger<UserManager<WrestleStatUser>> logger, IHttpContextAccessor contextAccessor)
: base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, tokenProviders, logger, contextAccessor)
{
}
}
public class WrestleStatRoleManager : RoleManager<WrestleStatRole>
{
public WrestleStatRoleManager(IRoleStore<WrestleStatRole> store, IEnumerable<IRoleValidator<WrestleStatRole>> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, ILogger<RoleManager<WrestleStatRole>> logger, IHttpContextAccessor contextAccessor) : base(store, roleValidators, keyNormalizer, errors, logger, contextAccessor)
{
}
}
And here's my startup.cs:
services.AddIdentity<WrestleStatUser, WrestleStatRole>()
.AddUserStore<WrestleStatUserStore>()
.AddUserManager<WrestleStatUserManager>()
//.AddRoleStore<RoleStore>()
.AddRoleManager<WrestleStatRoleManager>()
.AddDefaultTokenProviders();
What am I missing here? The error says something about the RoleManager, I've already defined my custom RoleManager...