/orleans:orleans-multiservice-patternfrom orleans
Modular-monolith pattern for Microsoft Orleans 10 — host multiple logical services inside one physical silo with project/namespace/dependency rules enabling later extraction to separate microservices. Scaffolds Apis/Contracts/Service projects with strict dependency directions.
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.
None: SKILL.md is the whole skill.
Use when building a Microsoft Orleans 10 backend and you want the productivity of a monolith (one deployable, in-process grain calls) with the optionality of microservices (any logical service can be extracted into its own physical microservice later, with minimal code changes). The pattern is a direct application of Martin Fowler's MonolithFirst and Conway's Law to Orleans.
Apply when:
Avoid when:
A single deployable Orleans microservice (physical host / silo) that contains one or more logical services. Named for the team or product area, e.g. TeamA → eShopTeamA. The multiservice name is used in:
Apis and Contracts assembly namesA functionally cohesive group of Orleans grains plus its related API endpoints, addressed exclusively through its public grain contracts. Examples: CatalogService, BasketService. Each logical service is three projects:
| Project | Public surface | Purpose |
|---|---|---|
Contracts.<Service>Contract | Everything | Grain contract interfaces — the only intended public face of the service |
<Service>Service | Restricted (see below) | Grain implementations |
Apis.<Service>Api | Everything | ASP.NET Core endpoints exposing the service over HTTP |
In the grain implementation project (<Service>Service), public is allowed only for:
This prevents other projects from calling service internals directly — they must go through grain contracts.
The project graph enforces four rules. Keep these invariants on every change:
Apis.<S>Api → Contracts.<S>Contract, Apis.<S>Api → <S>Service, <S>Service → Contracts.<S>Contract. Nothing else.Apis.<service>Api; public grain contracts live in Contracts.<service>Contract; grain implementations live in <service>Service.internal.These rules are what make extraction cheap later. Breaking them pulls the cost of extraction back to the present.
--allow-scripts Yes)Modern.CSharp.Templates installed:dotnet new install Modern.CSharp.Templates
dotnet new mcs-orleans-multiservice \
--RootNamespace Company.Product \
--Multiservice TeamA \
--Logicalservice Catalog \
--allow-scripts Yes
| Option | Purpose | Convention |
|---|---|---|
-R, --RootNamespace | Prefix (no trailing dot) for every project's root namespace. | <Company>.<Product|Technology> |
-M, --Multiservice | Name (without Service suffix) of the multiservice. Used in the solution name and as suffix for Apis.* and Contracts.* assembly names. | [<Product|Technology>]<TeamName> |
-L, --Logicalservice | Name (without Service suffix) of the first logical service to scaffold inside the multiservice. | e.g. Catalog, Basket |
| Option | Purpose | Default |
|---|---|---|
--allow-scripts | Run post-action PowerShell scripts (needed for full project graph) | Prompt — pass Yes in CI |
-n, --name | Output project root name | from --Multiservice |
-o, --output | Output folder | current directory |
For --RootNamespace Company.Product --Multiservice TeamA --Logicalservice Catalog:
Company.Product.TeamA.sln
├── .editorconfig ← extended Modern C# 14 baseline + Orleans rules
├── src/
│ ├── Apis/
│ │ └── Apis.CatalogApi/ ← ASP.NET Core endpoints
│ ├── Contracts/
│ │ └── Contracts.CatalogContract/ ← public grain interfaces
│ ├── Services/
│ │ └── CatalogService/ ← grain implementations (restricted public)
│ └── Host/
│ └── TeamAHost/ ← Orleans silo + endpoint composition
├── AddLogicalService.ps1 ← script to add more logical services
└── ...
Namespaces follow the prefix + service pattern:
Company.Product.Apis.CatalogApiCompany.Product.Contracts.CatalogContractCompany.Product.CatalogServiceCompany.Product.TeamAHost.editorconfigThe solution root includes an extended .editorconfig based on the mcs-editorconfig baseline (modern C# 14 formatting, naming, and preview-analyzer severities) with additional Orleans-specific rules layered on top. This means:
dotnet new mcs-editorconfig in this solution — the bundled file supersedes it..csproj flags documented in the dotnet-modern-csharp-editorconfig skill (Nullable=enable, TreatWarningsAsErrors=true, AnalysisLevel=preview-All, EnforceCodeStyleInBuild=true) still apply and are required for the bundled .editorconfig severities to take effect on dotnet build. Add them to Directory.Build.props at the solution root if not already present in the generated project files..editorconfig file.See the companion dotnet-modern-csharp-editorconfig skill for the baseline opinions (no underscore prefix on private fields, modern-idiom severities, etc.) — the bundled Orleans version inherits all of them.
Run the script generated alongside the solution:
.\AddLogicalService.ps1 Basket
This produces the three projects for the new logical service (Apis.BasketApi, Contracts.BasketContract, BasketService), registers them in the solution, and wires them into the existing host.
A service that needs another service's data calls it via its grain contract — the same as any Orleans grain call:
// Inside CatalogService, calling BasketService
public class CatalogGrain(IGrainFactory grainFactory) : Grain, ICatalogGrain
{
public async Task AddToBasketAsync(string buyerId, int productId)
{
var basket = grainFactory.GetGrain<IBasketGrain>(buyerId);
await basket.AddItemAsync(productId);
}
}
This is an in-silo Orleans grain call — no HTTP, no serialization overhead (with [Immutable] on arguments).
Importantly: the calling service's project references Contracts.BasketContract — not BasketService. That is what keeps the extraction cheap later.
When load, team ownership, or deploy cadence requires extracting a logical service:
Create a new multiservice containing only the service being extracted (e.g. TeamB containing Basket):
dotnet new mcs-orleans-multiservice \
--RootNamespace Company.Product \
--Multiservice TeamB \
--Logicalservice Basket \
--allow-scripts Yes
Remove the Basket logical service from the original multiservice.
In services that still call Basket (e.g. CatalogService), replace the in-silo grain-call path with a generated HTTP client (typically via OpenAPI spec from Apis.BasketApi) inside a thin adapter grain such as BasketServiceClientGrain. The rest of the calling code — which only saw the IBasketGrain contract interface — can often remain unchanged if the adapter implements the same contract.
Because step 3 is the only code change at the call site, extraction stays cheap — the structural rules from section 3 are what make this possible.
The pattern deliberately trades a small amount of up-front project overhead for two things:
For the philosophical background, see Fowler's MonolithFirst and Conway's Law.
Contracts.<S>Contract project — grep the .csproj graph for illegal references.<S>Service projects expose only what section 2 allows.AddLogicalService.ps1 step in a throwaway branch.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
orleans, modular-monolith, microservices, monolithfirst, conways-law
Other plugins' skills for the same job
npx claudepluginhub vincenth-net/dotnet-agentic-engineering --plugin orleans3 skills in this plugin
/orleans-multitenantMultitenancy for Microsoft Orleans 10 with the Orleans.Multitenant NuGet package — per-tenant grain storage and tenant separation of grain calls and streams. Use when an Orleans app needs multitenancy, tenant isolation or per-tenant storage (e.g. multi-tenant SaaS), even if the package is not referenced yet; this skill adds it. Also use in a repo that references Orleans.Multitenant when getting grains or streams, configuring storage or streams, subscribing to streams, or upgrading from 4.x./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.