依赖注入 – 类型RoleStore不能分配给服务IRoleStore
我正在尝试使用MVC5和EF6为项目设置依赖注入Autofac.
我很难弄清楚如何正确地解耦EntityFramework.RoleStore< EntityFramework.IdentityRole>实现. 这是我试过的: 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>>())); 完整的错误消息:
派对迟到了,但这对Autofac来说很有用:
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole,string>>(); 我的完整模块供参考: builder.RegisterType<UserStore<ApplicationUser>>().As<IUserStore<ApplicationUser>>(); builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole,string>>(); builder.RegisterType<ApplicationUserManager>(); builder.RegisterType<ApplicationRoleManager>(); 我正在使用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) { } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |