Reputation: 4302
I'm getting a few compiler errors about my bindings with Ninject
. This is the code:
kernel.Bind<IUserStore<ApplicationUserStore>>().To<UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>>().InRequestScope();
kernel.Bind<IRoleStore<ApplicationRoleStore>>().To<RoleStore<ApplicationRole, int, ApplicationUserRole>>().InRequestScope();
And these are the compiler errors:
Error 5 The type 'MyNamespace.Data.ApplicatonRoleStore' cannot be used as type parameter 'TRole' in the generic type or method 'Microsoft.AspNet.Identity.IRoleStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonRoleStore' to 'Microsoft.AspNet.Identity.IRole'.
Error 6 The type 'MyNamespace.Data.ApplicatonRoleStore' cannot be used as type parameter 'TRole' in the generic type or method 'Microsoft.AspNet.Identity.IRoleStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonRoleStore' to 'Microsoft.AspNet.Identity.IRole'.
Error 2 The type 'MyNamespace.Data.ApplicatonUserStore' cannot be used as type parameter 'TUser' in the generic type or method 'Microsoft.AspNet.Identity.IUserStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonUserStore' to 'Microsoft.AspNet.Identity.IUser'.
Error 3 The type 'MyNamespace.Data.ApplicatonUserStore' cannot be used as type parameter 'TUser' in the generic type or method 'Microsoft.AspNet.Identity.IUserStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonUserStore' to 'Microsoft.AspNet.Identity.IUser'.
Error 4 The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' to 'Microsoft.AspNet.Identity.IRoleStore'.
Error 1 The type 'Microsoft.AspNet.Identity.EntityFramework.UserStore' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.UserStore' to 'Microsoft.AspNet.Identity.IUserStore'.
By default the asp.net-identity
system uses the guid for primary key. I altered that to use ints instead. I can see some errors about Microsoft.AspNet.Identity.IRole<string>
.
EDIT: These are the classes:
public class ApplicationRoleStore : RoleStore<ApplicationRole, int, ApplicationUserRole>
{
public ApplicationRoleStore(ApplicationDbContext context)
: base(context)
{ }
}
public class ApplicationUserStore :
UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationUserStore(ApplicationDbContext context)
: base(context)
{ }
}
Upvotes: 1
Views: 2108
Reputation: 4302
I figured it out. In case someone else stumbles into this, this is how:
kernel.Bind<IAuthenticationManager>().ToMethod(c => HttpContext.Current.GetOwinContext().Authentication); //.InRequestScope();
kernel.Bind<IRoleStore<ApplicationRole, int>>().To<RoleStore<ApplicationRole, int, ApplicationUserRole>>()
.WithConstructorArgument("context", context => kernel.Get<ApplicationDbContext>());
kernel.Bind<IUserStore<ApplicationUser, int>>()
.To<UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>>()
.WithConstructorArgument("context", context => kernel.Get<ApplicationDbContext>());
Not sure if IAuthenticationManager
should be InRequestScope
, but for now I left that part out.
And for the managers you'd to it like this:
kernel.Bind<UserManager<ApplicationUser, int>>().ToSelf().InRequestScope();
kernel.Bind<RoleManager<ApplicationRole, int>>().ToSelf().InRequestScope();
Upvotes: 1