TenantId

Marks a field or property as containing the tenant identifier for multi-tenant applications.

The tenant ID identifies which tenant (organization, customer, etc.) the data belongs to. This annotation enables automatic tenant context propagation and data isolation in multi-tenant systems.

The framework uses this annotation to:

  • Automatically set tenant context from requests

  • Isolate data access by tenant boundaries

  • Generate tenant-specific routing and storage

  • Enforce tenant-based security policies

Example usage:

@AggregateRoot
class UserAggregate(
@AggregateId
val userId: String,

@TenantId
val tenantId: String // Which organization this user belongs to
)

// Command that operates within a tenant context
data class CreateUserCommand(
@AggregateId
val userId: String,

@TenantId
val tenantId: String, // Automatically populated from request context

val email: String,
val name: String
)

See also

for aggregates with fixed tenant IDs

for the default tenant identifier