Open Closed

Use Host admin to manage all tenant data #9010


User avatar
0
LiSong created

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)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    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 use CurrentTenant.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.");
        }
    }
    
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 20, 2025, 18:00