RoleStore <IdentityRole>类型不能分配给服务IRoleStore <IRole>

Att*_*asz 5 dependency-injection autofac entity-framework-6 asp.net-mvc-5

我正在尝试使用MVC5和EF6为项目设置依赖注入Autofac.

我很难弄清楚如何正确地解耦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>>()));
Run Code Online (Sandbox Code Playgroud)

完整的错误消息:

类型'Microsoft.AspNet.Identity.EntityFramework.RoleStore 1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]' is not assignable to service 'Microsoft.AspNet.Identity.IRoleStore1 [[Microsoft.AspNet.Identity.IRole,Microsoft.AspNet.Identity.Core,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35]]'.

Pet*_*teG 13

派对迟到了,但这对Autofac来说很有用:

builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>();
Run Code Online (Sandbox Code Playgroud)

我的完整模块供参考:

builder.RegisterType<UserStore<ApplicationUser>>().As<IUserStore<ApplicationUser>>();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>();
builder.RegisterType<ApplicationUserManager>();
builder.RegisterType<ApplicationRoleManager>();  
Run Code Online (Sandbox Code Playgroud)

我正在使用UserManager和RoleManager的包装器

public class ApplicationUserManager : UserManager<ApplicationUser>
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store)
        : base(store)
    {
    }
}

public class ApplicationRoleManager : RoleManager<IdentityRole>
{
    public ApplicationRoleManager(IRoleStore<IdentityRole, string> roleStore)
        : base(roleStore)
    {            
    }       
}
Run Code Online (Sandbox Code Playgroud)