2016-06-08 209 views
1

嘿,我试图将IRoleStore绑定到Rolestore,但我不断收到错误。我使用相同的代码应用程序用户和顺利,但作为例子,我将展示一个藏汉这里:依赖注入RoleStore与ninject

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

有什么想法?

回答

1

盲拍,但你可以尝试:

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

根据RoleStore documentation Rolestore的实现IRoleStore<TRole, string>,不IRoleStore<TRole>

+0

我尝试这样做,它确实是固定的错误,但我重做了整个角色的事情,所以它不再是相关的。但无论如何,它确实解决了它! :) –