Skip to content
bitzorcas
中EN

Concept

Multitenancy Deep Dive: 8-Step Resolution Chain & Data Isolation

Deep dive into BitzOrcas.Modern multitenancy: 8-step tenant resolution hierarchy, automated dual ORM global query filters, and operator impersonation sandboxes.

Last updated

In multi-tenant SaaS environments, tenant data isolation is an immutable security invariant. BitzOrcas.Modern enforces Ambient Context propagation + compile-time dual ORM Global Query Filters, injecting WHERE TenantId = @tenantId automatically during SQL generation.

8-Step Tenant Resolution Hierarchy

MatchedMissMatchedMissMatchedMissMatchedMissYesNo

Inbound HTTP Request

1. Host / Subdomain (lawfirm-alpha.bitz.com)

Set ICurrentTenant Ambient Scope

2. Request Headers (X-Tenant-Id / X-Tenant-Code)

3. JWT Claims (tenant_id / tid)

4. Query String Fallback (?tenantCode=xxx)

5. Public / Anonymous Endpoint?

Allow Anonymous Public Access

Reject: HTTP 400 (Tenant.Unresolved)


Dual ORM Compile-Time Global Tenant Isolation

For all aggregate roots inheriting from TenantAggregateRoot and decorated with [BitzTable], dual ORM adapters automatically register global tenant query filters:

Dual ORM Global Tenant Filter Behavior
// Developer-authored high-level query / read store call:
var matters = await noteReadStore.SearchAsync(fields, paging, sort, cancellationToken);
// SQL generated under the hood by EF Core and SqlSugar (automatically appending tenant scoping):
// SELECT * FROM LegalMatterIntake
// WHERE Status = 2 AND TenantId = 'lawfirm-alpha';

[!IMPORTANT] Zero Cognitive Overhead: Developers do not need to manually set TenantId or append WHERE TenantId = ... clauses when authoring queries or inserting records. The pipeline and persistence adapters inject tenant scopes automatically, physically eliminating cross-tenant Insecure Direct Object Reference (IDOR) vulnerabilities.


Summary

Automatic SQL injection of TenantId guards against Insecure Direct Object References (IDOR) without developer boilerplate.

100%

Scroll or use controls to zoom · drag when enlarged · double-click for 100% / 200%