RoleStore 使用 StructureMap 抛出错误
RoleStore throws error with StructureMap
当我尝试使用 Asp.Net Identity RoleStore 并将 StructureMap 用作 DI 容器时,UserStore 工作正常,但 RoleStore 在编译时抛出错误。
//works fine
cfg.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
//does NOT work
cfg.For<IRoleStore<IdentityRole>>().Use<RoleStore<IdentityRole>>();
抛出以下错误
The type
'Microsoft.AspNet.Identity.EntityFramework.RoleStore'
cannot be used as type parameter 'TConcreteType' in the generic type
or method
'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression.Use()'.
There is no implicit reference conversion from
'Microsoft.AspNet.Identity.EntityFramework.RoleStore'
to
'Microsoft.AspNet.Identity.IRoleStore'.
因为 RoleStore<TRole>
不是从 IRoleStore<TRole>
实现的。实际上它是从 IRoleStore<TRole, TKey>
开始实现的。因此试试这个:
cfg.For<IRoleStore<IdentityRole,string>>().Use<RoleStore<IdentityRole>>();
当我尝试使用 Asp.Net Identity RoleStore 并将 StructureMap 用作 DI 容器时,UserStore 工作正常,但 RoleStore 在编译时抛出错误。
//works fine
cfg.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
//does NOT work
cfg.For<IRoleStore<IdentityRole>>().Use<RoleStore<IdentityRole>>();
抛出以下错误
The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter 'TConcreteType' in the generic type or method 'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression.Use()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' to 'Microsoft.AspNet.Identity.IRoleStore'.
因为 RoleStore<TRole>
不是从 IRoleStore<TRole>
实现的。实际上它是从 IRoleStore<TRole, TKey>
开始实现的。因此试试这个:
cfg.For<IRoleStore<IdentityRole,string>>().Use<RoleStore<IdentityRole>>();