[英]Multi-tenant resolve tenant context in admin site
I'm developing a multi-tenant application in dot net core 2.1. 我正在点网核心2.1中开发一个多租户应用程序。 I have used the identity framework for user management. 我已经使用身份框架进行用户管理。 I have two web projects and two data context for tenant and system. 我有两个Web项目以及两个用于租户和系统的数据上下文。
SystemDb (SystemDbContext)- central database
TenantDb (TenantDbContext)- tenant (this has TenantId filter)
When I create a tenant from system portal, I want to create a default admin user in tenant database. 从系统门户创建租户时,我想在租户数据库中创建默认的admin用户。 I want to know what is the best way to resolve the tenant data context. 我想知道解决租户数据上下文的最佳方法是什么。 Tenant Entity has the connection to the database. 租户实体具有与数据库的连接。
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
}
}
您可以将租户上下文本身放置在其他项目中,并在System项目中引用生成的dll文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.