Finbuckle.MultiTenant icon indicating copy to clipboard operation
Finbuckle.MultiTenant copied to clipboard

Shared entities and database resolver

Open scharada opened this issue 3 years ago • 2 comments

one of the cases i am struggling to solve the correct way is forcing a query on specific entities to be executed against a shared database no matter who the tenant is.

one of the ideas i had is to use an attribute or an interface (ISharedEntity) to decorate the entity or make it inherit from the interface. when resolving the tenant database, if the entity being queried is decorated with the attibute or is of type ISharedEntity, the database connection is executed against a shared database common to all tenants and owned by the supertenant ... one of the scenarios where this is needed is when you want to force a global configuration or a value to all tenants in a SaaS platform... the scenario get more complex when considering the data isolation (shared central, per tenant .... ) and an entity can or must be be present for the tenant and for the supertenant and the database strategy ... a classic example : think of a supertenant who is a payment provider for all tenants, payment records belong to the supertenant therefore, related tables must be created accordingly, at the same time, a tenant must have access to some payment data for his records, therefore some payment records must be crested in his database ...

any thoughts/ideas on how to achieve/implement this ?

scharada avatar Jul 05 '22 11:07 scharada

If you don't mark an entity as [MultiTenant] (or use the fluid syntax) then all queries on it are global, even on a MultiTenantDbContext or similar. So for that entity all tenants see all rows. Is that not quite what you were going for?

AndrewTriesToCode avatar Jul 19 '22 02:07 AndrewTriesToCode

it does partially. but it would not work for the scenario i described (all tenants seeing all payment records) although i could use the tenantid to filter out the results... i guess i have to play with all cases to see the behavior, or maybe use some UoW logic to force a query against a specific db ...

thank you for your response.

scharada avatar Jul 23 '22 22:07 scharada

This issue has been automatically marked for closure because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 02 '22 06:11 stale[bot]