【问题标题】:Multi-tenant resolve tenant context in admin site多租户解析管理站点中的租户上下文
【发布时间】:2018-07-07 03:22:10
【问题描述】:

我正在 dot net core 2.1 中开发一个多租户应用程序。我已经使用身份框架进行用户管理。我有两个 Web 项目和两个用于租户和系统的数据上下文。

SystemDb (SystemDbContext)- central database

TenantDb (TenantDbContext)- tenant (this has TenantId filter)

当我从系统门户创建租户时,我想在租户数据库中创建一个默认管理员用户。我想知道解决租户数据上下文的最佳方法是什么。租户实体已连接到数据库。

public class TenantManagementService: ITenantManagementService
{
    private readonly ISystemDbContext _systemDbContext;
    private readonly UserManager<SystemUser> _userManager;

    public InsertTenantDetailsCommandHandler(ISystemDbContext systemDbContext, UserManager<SystemUser> userManager)
    {
        _systemDbContext = systemDbContext;
    }

    public async Task CreateTenant(Tenant tenant)
    {
        await _systemDbContext.Tenants.AddAsync(tenant);
        await _systemDbContext.SaveChangesAsync();

        // I need to create default user in tenantDbContext
    }
}

【问题讨论】:

    标签: c# entity-framework asp.net-identity multi-tenant


    【解决方案1】:

    您可以将租户上下文单独放在不同的项目中,并在 System 项目中引用生成的 dll 文件。

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 2021-12-24
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 2023-04-10
      • 1970-01-01
      相关资源
      最近更新 更多