Open Closed

How TenantId is acquiring current tenant value? #9337


User avatar
0
jlanza10 created

Hi,

I noticed something about management of tenants that catched my atention. It's not a problem but i'm just trying to understand how is it working. I proceed to explain myself with some examples:

Imagine i have this class

When I instantiate it by calling the constructor the property TenantId is acquiring the value of my current tenant even before trying to insert it or saving changes with unit of work. I readed your documentation about this (https://abp.io/docs/latest/framework/architecture/multi-tenancy#when-to-set-the-tenantid) and learned you do it on the base Entity class but i would like to know how you do it. Could you let me know how is it done on that class?

Thanks!


1 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, ABP Framework automatically sets tenantId when you directly or indirectly implement the IMultiTenant interface.

    There is an EntityHelper.TrySetTenantId method (https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/EntityHelper.cs#L281-L300), which gets the current tenant id and sets it from the current scope.

    ABP determines the current tenant from one of its providers (https://abp.io/docs/latest/framework/architecture/multi-tenancy#determining-the-current-tenant) and then basically sets it, so while creating an entity or filtering it it passes to the query/command.

    Regards.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on June 13, 2025, 11:37