如何使用dotnet核心中的Identity将另一个参数传递给扩展的userStore类

时间:2017-04-21 17:40:42

标签: c# .net-core identity

我正在实施一个简单的多租户应用,为此,我以这种方式扩展了UserStore类:

public class ApplicationUserStore : UserStore<OmniUser>
{
    public string TenantId { get; set; }

    public ApplicationUserStore(OmniDbContext context, IdentityErrorDescriber describer = null)
        : base(context, describer) { }

    // overrided methods
}

要配置依赖注入以使用扩展UserStore,我将此代码添加到Startup ConficureServices方法中:

services.AddIdentity<OmniUser, IdentityRole>()
 .AddEntityFrameworkStores<OmniDbContext>()
 .AddDefaultTokenProviders()
 .AddUserStore<ApplicationUserStore>(); // Extended UserStore  

我可以看到服务已正确实例化,并且覆盖的方法在ApplicationUserStore上运行良好。

问题是我需要将TenantId传递给我的UserStore。我知道我可以创建另一个接受另一个变量的构造函数,但后来我不知道如何使用DI实例化它。

我可以创建一个快捷方式并通过UserManager类手动定义它,但似乎我无法访问UserStore实例中的UserManager

我怎样才能以优雅的方式做到这一点?我试图避免手动实例化我的自定义UserStoreUserManager

谢谢。

0 个答案:

没有答案
相关问题