是否有机会使用带有AspNet核心标识的IdentityManager?
我没有找到任何针对AspNetCoreidentity的IIdentityManagerService的实现。
或者,使用AspnetCore身份时是否有任何IdentityManager的替换?
谢谢。
答案 0 :(得分:1)
是的,您可以使用IdentityManager管理您的AspNetIdentity用户。
IdentityManager本身有一个名为IdentityManager.AspNetIdentity的实现。您可能需要阅读an article describing your scenario by Scott Hanselman。
您基本上想要做的是加载继承自AspNetIdentityManagerService
public class ApplicationIdentityManagerService : AspNetIdentityManagerService<ApplicationUser, string, IdentityRole, string>
{
public ApplicationIdentityManagerService(ApplicationUserManager userMgr, ApplicationRoleManager roleMgr) : base(userMgr, roleMgr)
{
// Nothing
}
}
然后您可以将其插入工厂:
app.Map("/users", idm =>
{
var factory = new IdentityManagerServiceFactory();
factory.IdentityManagerService = new Registration<IIdentityManagerService, ApplicationIdentityManagerService>();
factory.Register(new Registration<ApplicationUserManager>());
factory.Register(new Registration<ApplicationUserStore>());
factory.Register(new Registration<ApplicationRoleManager>());
factory.Register(new Registration<ApplicationRoleStore>());
factory.Register(new Registration<ApplicationDbContext>(resolver => new ApplicationDbContext("dbase")));
factory.Register(new Registration<ApplicationDbContext>());
idm.UseIdentityManager(new IdentityManagerOptions {
Factory = factory
});
});
在more complete example上找到IdentityManager AspNetIdentity GitHub repo。