我試圖建立依賴注入Autofac使用MVC5和EF6項目。類型Rolestore的<IdentityRole>是不能分配給服務IRoleStore <IRole>
我很難搞清楚如何正確解耦EntityFramework.RoleStore <EntityFramework.IdentityRole>的實現。
我想只有在Identity.IRoleStore <Identity.IRole>的依賴,但我知道,對於通用類我需要指定具體的實現,而不是接口。
這是我的嘗試:
builder.RegisterType<IdentityRole>().As<IRole>();
builder.RegisterType<RoleManager<IRole>>();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IRole>>();
builder.Register(c => new RoleManager<IRole>(c.Resolve<IRoleStore<IRole>>()));
完整的錯誤消息:
類型「Microsoft.AspNet.Identity.EntityFramework.RoleStore
1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]' is not assignable to service 'Microsoft.AspNet.Identity.IRoleStore
1 [Microsoft.AspNet.Identity。 IRole,Microsoft.AspNet.Identity.Core,版本= 1.0.0.0,文化=中性公鑰= 31bf3856ad364e35]]」。