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

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

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;
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    Siyeza created

    Thank you

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)