Interface ITenantMembershipStore
- Namespace
- Stratara.Abstractions.Multitenancy
- Assembly
- Stratara.Abstractions.dll
Persistence contract for user↔tenant memberships (TenantMembership) — the authorization-plane record of which tenants a user belongs to and which tenant-scoped roles the user holds in each.
public interface ITenantMembershipStore
- Extension Methods
Remarks
The store is deliberately relational-shaped (read-your-write consistency at sign-in time), but implementations are free to maintain the underlying data from domain events: a consumer whose membership changes are event-sourced keeps emitting its events and updates the store from a projection or saga instead of calling SetMembershipAsync(TenantMembership, CancellationToken) inline.
Both directions of the relationship are first-class: GetMembershipsAsync(Guid, CancellationToken) answers "which tenants may this user access" (sign-in tenant resolution, tenant switching) and GetMembersAsync(Guid, CancellationToken) answers "who belongs to this tenant" (administration, cascade cleanup). The sweep methods (RemoveAllMembershipsAsync(Guid, CancellationToken), RemoveAllMembersAsync(Guid, CancellationToken)) exist so user- and tenant-erasure flows can clear the membership plane in one call.
Methods
GetActiveTenantAsync(Guid, CancellationToken)
Gets the tenant the user has explicitly selected as the active one for sign-in, or
null when the user never made a selection (callers fall back to the user's only —
or first — active membership).
Task<Guid?> GetActiveTenantAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose selection to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
GetMembersAsync(Guid, CancellationToken)
Gets every membership of the tenant — the reverse lookup ("who belongs to this tenant").
Task<IReadOnlyList<TenantMembership>> GetMembersAsync(Guid tenantId, CancellationToken cancellationToken = default)
Parameters
tenantIdGuidThe tenant whose members to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<IReadOnlyList<TenantMembership>>
The tenant's memberships; empty when the tenant has no members.
GetMembershipAsync(Guid, Guid, CancellationToken)
Gets the user's membership in one specific tenant.
Task<TenantMembership?> GetMembershipAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose membership to load.
tenantIdGuidThe tenant to look the membership up in.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<TenantMembership>
The membership, or
nullwhen the user does not belong to the tenant.
GetMembershipsAsync(Guid, CancellationToken)
Gets every membership the user holds, regardless of status.
Task<IReadOnlyList<TenantMembership>> GetMembershipsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose memberships to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<IReadOnlyList<TenantMembership>>
The user's memberships; empty when the user belongs to no tenant.
RemoveAllMembersAsync(Guid, CancellationToken)
Removes every membership of the tenant — the membership-plane step of a tenant-erasure sweep. No-op when the tenant has no members.
Task RemoveAllMembersAsync(Guid tenantId, CancellationToken cancellationToken = default)
Parameters
tenantIdGuidThe tenant whose memberships to remove.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
RemoveAllMembershipsAsync(Guid, CancellationToken)
Removes every membership the user holds — the membership-plane step of a user-erasure (GDPR) sweep. No-op when the user holds none.
Task RemoveAllMembershipsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose memberships to remove.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
RemoveMembershipAsync(Guid, Guid, CancellationToken)
Removes the user's membership in one tenant. No-op when no such membership exists.
Task RemoveMembershipAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose membership to remove.
tenantIdGuidThe tenant to remove the membership from.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
SetActiveTenantAsync(Guid, Guid, CancellationToken)
Persists the user's active-tenant selection — the tenant-switch operation for users with more than one membership. Implementations enforce the membership guard: the selection is rejected when the user holds no Active membership in the target tenant.
Task SetActiveTenantAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user switching tenants.
tenantIdGuidThe tenant to make active.
cancellationTokenCancellationTokenToken to observe while persisting.
Returns
Exceptions
- InvalidOperationException
The user holds no active membership in
tenantId.
SetMembershipAsync(TenantMembership, CancellationToken)
Task SetMembershipAsync(TenantMembership membership, CancellationToken cancellationToken = default)
Parameters
membershipTenantMembershipThe membership to persist; its role set and status replace any existing values.
cancellationTokenCancellationTokenToken to observe while persisting.