Table of Contents

Class TenantScopedKey

Namespace
Excalibur.Data
Assembly
Excalibur.Data.Abstractions.dll

The framework's single injective encoding for composing a tenant term into a string storage key.

public static class TenantScopedKey
Inheritance
TenantScopedKey
Inherited Members

Remarks

Joining terms with a bare separator — "t:" + tenantId + ":" + id — is not injective, because neither term is validated against any charset. A term containing the separator shifts across the boundary and two distinct tuples render one key:

tenant "acme"     record "eu:order-42"   ->  t:acme:eu:order-42
tenant "acme:eu"  record "order-42"      ->  t:acme:eu:order-42     IDENTICAL

Two tenants addressing one key is not a formatting problem: one tenant can read, write and irreversibly erase another's records by passing a single ordinary string.

'%' is escaped FIRST, and that is what makes the encoding reversible. Escaping only ':' would map the distinct terms a:b and a%3Ab onto one key — a collision introduced by the escaping itself.

The encoding is the IDENTITY on any term containing neither ':' nor '%', which is what makes it safe to adopt on persisted keys: an ordinary identifier encodes to itself, byte for byte, so no stored record is orphaned. The only keys whose bytes change are the ambiguous ones, which had no single correct owner to begin with.

Rejecting ':' is not an option and this is a compatibility constraint, not a preference. A shipped conformance arm exercises tenant a:b as a valid, supported case. Banning the separator would split the framework's own definition of a valid tenant id — the same identifier accepted by the inbox and refused by the event store.

The encoding itself is not implemented here. It lives on SegmentedKey, in the one package every affected subsystem can reach, because it had grown three separate times — once per subsystem that could not reference the others. This type adds the tenant-scope contract on top of it: the Prefix that marks a key as tenant-scoped and keeps range probes over the tenant-scoped key space working. It delegates rather than duplicates, so there is no second encoding to drift.

Fields

Prefix

Marks a key as tenant-scoped. Unchanged from the previous composition, so range probes over the tenant-scoped key space continue to work.

public const string Prefix = "t:"

Field Value

string

Methods

Compose(string, string)

Composes the tenant-scoped storage key for id within tenantId.

public static string Compose(string tenantId, string id)

Parameters

tenantId string

The owning tenant's term.

id string

The record identifier within that tenant.

Returns

string

A key no other tenant can produce for any record identifier.

Compose(string, params string[])

Composes a tenant-scoped key from a tenant term and one or more further terms.

public static string Compose(string tenantId, params string[] segments)

Parameters

tenantId string

The owning tenant's term.

segments string[]

The remaining terms, in order.

Returns

string

A key no other tenant, and no other term sequence, can produce.

EscapeSegment(string)

Encodes one term so that no character in it can be mistaken for a segment boundary.

public static string EscapeSegment(string value)

Parameters

value string

The term to encode.

Returns

string

The term with '%' and ':' escaped — identical to value when it contains neither.

Remarks

Exposed because stores compose different shapes — some join a tenant with one identifier, others with an aggregate type as well. Each shape stays injective as long as every term goes through here, and the separator between them is a raw ':'.

UnescapeSegment(string)

public static string UnescapeSegment(string value)

Parameters

value string

The encoded term.

Returns

string

The original term.

Remarks

':' is unescaped BEFORE '%', mirroring the encode order. Doing it the other way round would turn an encoded %253A — a literal "%3A" in the original term — into a separator.