2016-06-08 206 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

我嘗試這樣做,它確實是固定的錯誤,但我重做了整個角色的事情,所以它不再是相關的。但無論如何,它確實解決了它! :) –