Litsher - Nathan
Litsher - Nathan

Reputation: 275

Dependency injection RoleStore with ninject

Hey I am trying to bind the IRoleStore to the Rolestore but I keep getting an error. I use the same code for the application user and that goes well, but as example I'll show that one here aswell :

kernel.Bind<IRoleStore<ApplicationRole>>().To<RoleStore<ApplicationRole>>()
    .WithConstructorArgument("context", 
        context => kernel.Get<InBuildingNavigatorDbContext>());
kernel.Bind<RoleManager<ApplicationRole>>().ToSelf().InRequestScope();

kernel.Bind<IUserStore<ApplicationUser>>().To<UserStore<ApplicationUser>>()
    .WithConstructorArgument("context", 
        context => kernel.Get<InBuildingNavigatorDbContext>());
kernel.Bind<UserManager<ApplicationUser>>().ToSelf().InRequestScope();

And I get the error:

The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore<InBuildingNavigator.Data.Models.ApplicationRole>' cannot be used as type parameter 'TImplementation' in the generic type or method 'IBindingToSyntax<IRoleStore<ApplicationRole>>.To<TImplementation>()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore<InBuildingNavigator.Data.Models.ApplicationRole>' to 'Microsoft.AspNet.Identity.IRoleStore<InBuildingNavigator.Data.Models.ApplicationRole>'.

Any thoughts?

Upvotes: 1

Views: 366

Answers (1)

jbl
jbl

Reputation: 15413

A blind shot, but you may try :

kernel.Bind<IRoleStore<ApplicationRole, string>>().To<RoleStore<ApplicationRole>>()
    .WithConstructorArgument("context", 
        context => kernel.Get<InBuildingNavigatorDbContext>());

According to RoleStore documentation RoleStore implements IRoleStore<TRole, string>, not IRoleStore<TRole>

Upvotes: 1

Related Questions