如何将 IdentityManager 与 AspNetCoreIdentity 一起使用

How to use IdentityManager with AspNetCoreIdentity

有机会使用 IdentityManager 和 AspNet Core Identity 吗?

我没有找到 AspNetCoreidentity 的 IIdentityManagerService 的任何实现。

或者,在使用 AspnetCore 身份时是否有 IdentityManager 的替代品?

谢谢。

是的,您可以使用 IdentityManager 来管理您的 AspNetIdentity 用户。

IdentityManager 本身有一个名为 IdentityManager.AspNetIdentity 的实现。您可能需要通读 an article describing your scenario by Scott Hanselman.

您本质上想要做的是加载继承自 AspNetIdentityManagerService

的 IdentityManagerService
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 on the IdentityManager AspNetIdentity GitHub repo.