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!

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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 v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.