Skip to main content
Table of Contents

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

userId Guid

The user whose selection to load.

cancellationToken CancellationToken

Token to observe while loading.

Returns

Task<Guid?>

The selected tenant, or null when no explicit selection exists.

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

tenantId Guid

The tenant whose members to load.

cancellationToken CancellationToken

Token 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

userId Guid

The user whose membership to load.

tenantId Guid

The tenant to look the membership up in.

cancellationToken CancellationToken

Token to observe while loading.

Returns

Task<TenantMembership>

The membership, or null when 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

userId Guid

The user whose memberships to load.

cancellationToken CancellationToken

Token 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

tenantId Guid

The tenant whose memberships to remove.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user whose memberships to remove.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user whose membership to remove.

tenantId Guid

The tenant to remove the membership from.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user switching tenants.

tenantId Guid

The tenant to make active.

cancellationToken CancellationToken

Token to observe while persisting.

Returns

Task

Exceptions

InvalidOperationException

The user holds no active membership in tenantId.

SetMembershipAsync(TenantMembership, CancellationToken)

Creates or replaces the membership identified by the record's UserId and TenantId (upsert).

Task SetMembershipAsync(TenantMembership membership, CancellationToken cancellationToken = default)

Parameters

membership TenantMembership

The membership to persist; its role set and status replace any existing values.

cancellationToken CancellationToken

Token to observe while persisting.

Returns

Task