/orleans:orleans-multitenantfrom orleans
Adds multitenancy to Microsoft Orleans 10 apps via Orleans.Multitenant: per-tenant grain storage, tenant-isolated grain calls and streams. Use when an Orleans app needs tenant isolation or per-tenant storage.
Ships in orleans. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use when a Microsoft Orleans 10 application needs multitenancy: each tenant's grain state in its own storage, and grain calls and streams that cannot cross tenants unless explicitly authorized. Orleans.Multitenant adds this to Orleans; do not hand-roll it with tenant prefixes in grain keys and per-call tenant checks.
Apply when any of these is true:
Orleans.Multitenant yet — add it (sections 3 and 4)Orleans.Multitenant and you write or change code that gets a grain or a stream, subscribes to a stream, or configures grain storage or stream providersOrleans.Multitenant from 4.x to 5.x; follow references/upgrade-4x-to-5x.mdOut of scope for the library, so the application must handle these:
IGrainWithStringKey grains can be tenant specificThis file covers the common path and the mistakes to avoid. Read the reference file before writing code for:
The API documentation of the installed version is in the NuGet package folder, by default ~/.nuget/packages/orleans.multitenant/<version>/lib/net10.0/Orleans.Multitenant.xml.
The tenant ID is part of the key of a tenant grain or tenant stream. Get every tenant grain and tenant stream with the tenant aware API. After that, use the regular Orleans API for grain calls, publishing, subscribing, resuming, unsubscribing and storing subscription handles.
| Where | Tenant grain | Tenant stream |
|---|---|---|
| In a tenant grain, same tenant | this.GetTenantGrainFactory().GetGrain<T>(key) | this.GetTenantStreamProvider(name).GetStream<T>(ns, key) |
| In a tenant grain, other tenant | this.GetTenantGrainFactory(tenantId).GetGrain<T>(key) | this.GetTenantStreamProvider(name, tenantId).GetStream<T>(ns, key) |
| Same tenant as another grain | factory.ForTenantOf(grain).GetGrain<T>(key) | |
| No tenant grain: cluster client, API endpoint, stateless worker, grain service | factory.ForTenant(tenantId).GetGrain<T>(key) | client.GetTenantStreamProvider(name, tenantId).GetStream<T>(ns, key) |
key is always the key within the tenant. Tenant IDs and keys within a tenant can be any string.
Do not:
GrainFactory.GetGrain<T>(key) or GetStreamProvider(name) for tenant grains and tenant streams. This compiles. The grain then belongs to the null tenant instead of the caller's tenant, so tenants share it; events on the stream are blocked (section 8)GetTenantId() and GetKeyWithinTenant(), which exist for a grain (IAddressable), a GrainId and a StreamIdOrleans.Multitenant 5.x; 5.0.1 or later when the stream provider serializes events as JSON instead of with the Orleans serializerAdd the package to the silo, client and grain implementation projects:
dotnet add package Orleans.Multitenant
The features are independent; add the ones the application needs. Any Orleans storage provider and any Orleans stream provider can be used.
siloBuilder
.AddMultitenantCommunicationSeparation() // Without this, grain calls and streams are not separated between tenants
.AddMultitenantGrainStorageAsDefault<AzureTableGrainStorage, AzureTableStorageOptions, AzureTableGrainStorageOptionsValidator>(
// Called during silo startup
(silo, name) => silo.AddAzureTableGrainStorage(name, options =>
options.TableServiceClient = new(connectionString)),
// Called on the first grain state access for a tenant in a silo
configureTenantOptions: (options, tenantId) =>
{
options.TableServiceClient = new(connectionString);
options.TableName = $"OrleansGrainState{tenantId}";
})
.AddMultitenantStreams("provider_name", (silo, name) => silo
.AddMemoryStreams<DefaultMemoryMessageBodySerializer>(name)
.AddMemoryGrainStorage(name));
AddMultitenantGrainStorage(name, ...) for a named provider. A regular storage provider can exist next to a multitenant onegetProviderParameters; see references/storage-providers.mdaddStreamProvider function, with .AddStreamFilter<MyStreamFilter>(name) after the stream provider. Never register it for that provider after AddMultitenantStreams; see references/stream-filters-and-start-position.mdclient.GetTenantStreamProvider(name, tenantId)A TenantStream<T> has the same methods as an Orleans IAsyncStream<T>. It deliberately is not an IAsyncStream<T>, so do not try to cast or convert it. Subscription handles are regular StreamSubscriptionHandle<T>s.
var stream = this.GetTenantStreamProvider("provider_name").GetStream<int>("stream_namespace", "stream_key_within_tenant");
await stream.OnNextAsync(1);
await stream.OnNextBatchAsync([2, 3]);
StreamSubscriptionHandle<int> handle = await stream.SubscribeAsync(OnNextAsync);
await handle.UnsubscribeAsync();
Task OnNextAsync(int item, StreamSequenceToken? token) { /* ... */ }
Explicit subscriptions: resume them when the grain is activated, as Orleans prescribes:
public override async Task OnActivateAsync(CancellationToken cancellationToken)
{
var stream = this.GetTenantStreamProvider("provider_name").GetStream<int>("stream_namespace", this.GetKeyWithinTenant());
foreach (var handle in await stream.GetAllSubscriptionHandles())
await handle.ResumeAsync(OnNextAsync);
}
Implicit subscriptions: either call SubscribeAsync on the tenant stream when the grain is activated, or implement IStreamSubscriptionObserver (namespace Orleans.Streams.Core) and use CreateTenantHandle<T>(), not Create<T>():
public async Task OnSubscribed(IStreamSubscriptionHandleFactory handleFactory)
{
var handle = handleFactory.CreateTenantHandle<int>();
await handle.ResumeAsync(this);
}
Stream key in a grain: pass this.GetKeyWithinTenant() to GetStream<T>(namespace, key), not this.GetPrimaryKeyString(); the latter includes the tenant ID. GetStream<T>(StreamId) does accept a stream ID of a tenant stream
Handles in grain state: supported, with the Orleans serializer and with the default JSON grain storage serializer
Streams that are not tenant specific: see references/null-tenant-and-tenant-unaware-streams.md
By default tenants cannot communicate, and only calls to Orleans.* grain interfaces are exempt. To allow specific access, pass an ICrossTenantAuthorizer factory:
.AddMultitenantCommunicationSeparation(_ => new CrossTenantAuthorizer())
class CrossTenantAuthorizer : ICrossTenantAuthorizer
{
public bool IsAccessAuthorized(string? sourceTenantId, string? targetTenantId)
=> string.Equals(sourceTenantId, "RootTenant", StringComparison.Ordinal); // The root tenant may access any tenant
}
IsAccessAuthorized is synchronous and runs when a grain calls a grain of another tenant, or gets a stream provider for another tenant. Keep it fast and in memory: do not call grains or do I/O in it, and do not block on async code. When the authorization data changes at runtime, keep it in an in-memory cache per silo that is refreshed in the background (get the cache from the IServiceProvider that the factory receives)IGrainCallTenantSeparator factory as the second parameter to control which grain calls need authorizationnull. To use such grains on purpose (e.g. grains whose keys are defined by third-party code), see references/null-tenant-and-tenant-unaware-streams.mdGrainFactory.GetGrain, .GetGrain< on a plain IGrainFactory or IClusterClient, and .GetStreamProvider(AddMultitenantCommunicationSeparation is present when tenants must be isolatedAddMultitenantStreamsUnauthorizedAccessException)| Symptom | Cause | Fix |
|---|---|---|
UnauthorizedAccessException: Tenant "A" attempted to access tenant "B" | A grain called a grain of another tenant, or got a stream provider for another tenant, without authorization. "NULL" is the null tenant: that grain was obtained with the regular IGrainFactory | Get the grain or stream as in section 2, or authorize the access (section 6) |
Events are published but never received; the silo log has an error with event ID TenantUnawareStreamApiUsed (... was not sent with the tenant aware API) | The event was published with GetStreamProvider on a multitenant stream provider | Publish with GetTenantStreamProvider |
The silo fails to start with an OrleansConfigurationException: ... stream filter ... was registered for it afterwards | A stream filter was registered after AddMultitenantStreams | Register it inside the addStreamProvider function (section 4) |
InvalidOperationException: Could not create storage provider ... for tenant ... | The storage provider has constructor parameters that are not registered as services | Pass getProviderParameters (section 4) |
ArgumentException: streamId ... for tenant ... cannot be retrieved from a stream provider for tenant ... | GetStream<T>(StreamId) was called with a stream ID of another tenant | Get the tenant stream provider for that tenant |
Events arrive with empty content (0, null), without an error | The stream provider serializes events as JSON and the package is older than 5.0.1 | Upgrade to 5.0.1 or later |
After an upgrade from 4.x, grain state fails to load with an exception that mentions TenantEvent | The state contains a subscription handle that 4.x stored | Follow step 3 in references/upgrade-4x-to-5x.md |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
orleans, multitenancy, tenant-isolation, grain-storage, saas
Other plugins' skills for the same job
3 skills in this plugin
/orleans-multiservice-patternModular-monolith pattern for Microsoft Orleans 10 — host multiple **logical services** inside one physical silo/microservice, with project/namespace/dependency rules that let any logical service later be extracted to its own physical microservice with minimal changes. Use when starting a new Orleans 10 backend for a single team, when deferring real microservices until genuinely needed (MonolithFirst), when organizing a codebase to follow Conway's Law, or when you want painless future migration from in-silo grain calls to generated OpenAPI HTTP clients. Scaffolds `Apis.<S>Api`, `Contracts.<S>Contract`, and `<S>Service` projects with strict dependency directions (Apis→Contracts, Apis→Service, Service→Contracts), plus a silo host. Generated by the `mcs-orleans-multiservice` template; add more logical services via `AddLogicalService.ps1 <name>` or `--Multiservice .`./orleans-result-patternConcise, version-tolerant result pattern for Microsoft Orleans 8+ grain calls. Return success/error without throwing exceptions — errors are `enum ErrorNr` + `string` message, fully Orleans-serialization-compatible, marked `[Immutable]` for zero-copy within-silo calls. Use when designing grain contracts that need non-exception flow control, when returning RFC7807 `ValidationProblemDetails` from ASP.NET Core, when avoiding `FluentResults`-style libraries that don't serialize cleanly under Orleans, or when you want implicit conversions (`return "ok"`, `return ErrorNr.NotFound`, `return (ErrorNr.NotFound, "Not found")`) and pattern-matching consumption. Generated by the `mcs-orleans-results` template, which drops `ErrorNr.cs` + `Result.cs` into the project that contains grain interfaces.npx claudepluginhub vincenth-net/dotnet-agentic-engineering --plugin orleans