Search code examples
c#entity-frameworkninjectowinidentity

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?


Solution

  • 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>