Base solution for your next web application
Open Closed

Determining current Tenant in Domain Layer #9160


User avatar
0
Siyeza created

Hi,

What is the recommended way for deternining the current Tenant for domain service operations that operate on tenant specific data? Should I rely on AbpSession being populated with current TenantId or should I explicitly specify the TenantId as a parameter in the domain service requests, and use CurrentUnitOfWork.SetTenantId()?

Thanks


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    You can use the following method to get TenantId

    protected virtual int? GetCurrentTenantIdOrNull()
    {
        if (CurrentUnitOfWorkProvider?.Current != null)
        {
            return CurrentUnitOfWorkProvider.Current.GetTenantId();
        }
    
        return AbpSession.TenantId;
    }
    
  • User Avatar
    0
    Siyeza created

    Thank you