【问题标题】:RoleStore throws error with StructureMapRoleStore 使用 StructureMap 引发错误
【发布时间】:2016-03-25 06:01:04
【问题描述】:

当我尝试使用 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>>(); 

抛出以下错误

类型 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' 不能用作泛型类型中的类型参数“TConcreteType” 或方法 'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression.Use()'。 没有隐式引用转换 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' 到 'Microsoft.AspNet.Identity.IRoleStore'。

【问题讨论】:

    标签: asp.net-mvc-5 asp.net-identity structuremap user-roles


    【解决方案1】:

    因为RoleStore&lt;TRole&gt; 不是从IRoleStore&lt;TRole&gt; 实现的。实际上它是从IRoleStore&lt;TRole, TKey&gt; 实现的。所以试试这个:

    cfg.For<IRoleStore<IdentityRole,string>>().Use<RoleStore<IdentityRole>>(); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      相关资源
      最近更新 更多