We want to use the host admin to manage all tenant data, for example, each tenant has their users, surveys and survey answers from users, the tenant admins can manage these data;
we want to enable the host admin to manage all users, surveys, survey answers from the host site
Is there a recommended way to implement this with ABP?
We could implement it by writing our own data repositories, but it feels like there might be an easier way.
1 Answer(s)
-
0
Hi,
It's possible but also it seems not stable.
ABP supports using database separation across tenants. Whenever you separate database for a tenant you'll not be able to combine all the data between tennats
In the scenario you'll use always same database;
You don't have to implement your own repositories. You can useCurrentTenant.Change()
method inside a using scope to change the tenant you want to access its data.using (CurrentTenant.Change(tenantId)) { return await _productRepository.GetCountAsync(); }
Check here: https://abp.io/docs/latest/framework/architecture/multi-tenancy#change-the-current-tenant
You can iterate all the tenants inside a foreach loop in this way:
var tenants = await _tenantRepository.GetListAsync(includeDetails: true); foreach (var tenant in tenants) { using (_currentTenant.Change(tenant.Id)) { var users = _userRepository.GetList(/*...*/); Logger.LogInformation($"Tenant {tenant.Name} has {users.Count} users."); } }