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:
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)
-
0
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.