ninject 的依赖注入 RoleStore

Dependency injection RoleStore with ninject

嘿,我正在尝试将 IRoleStore 绑定到 Rolestore,但我一直收到错误消息。我为应用程序用户使用了相同的代码,并且运行良好,但作为示例,我也会在此处展示一个代码:

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();

我收到错误:

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>'.

有什么想法吗?

盲目射击,但你可以试试:

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

根据 RoleStore documentation RoleStore 实现 IRoleStore<TRole, string>,而不是 IRoleStore<TRole>