method IMultiTenancyService.getRepositoryFor
Since 0.4.0
IMultiTenancyService.getRepositoryFor<Entity, Id = string>(
tenantId: string,
entity: string
): ITenantRepository<Entity, Id>

Create a tenant-scoped repository for the given entity type, scoped to the tenant id GIVEN — no IRequestContext required. This is the entry point for non-HTTP work (an ingress behaviour, a queue processor, a scheduled job), where no request exists to resolve a tenant from; the caller reads the tenant id from the work item's own payload. Modelled on prefixCacheKey — this interface's other ctx-free, id-taking member.

The id is TRUSTED INPUT: nothing resolves it, so a caller passing a user-controlled value bypasses the resolved tenant. On the HTTP path use getRepository, which reads the middleware-resolved ctx.request.tenant.

Type Parameters

Entity
Id = string

Parameters

tenantId: string

The tenant id to scope the repository to (trusted input)

entity: string

Entity name for scoping

Return Type

A tenant-scoped repository

Usage

import { type IMultiTenancyService } from "common/src/index.ts";