shinyorg/templates/shiny-mediator
Claude Code and agent skill by shinyorg/templates
- community
Checking that the SKILL.md file is still in the repository.
Generate Shiny Mediator handlers, contracts, middleware, and scaffold projects for .NET applications
Install
npx vskill@latest install shinyorg/templates/shiny-mediatorSKILL.md
The same SKILL.md was published earlier as shinyorg/templates/shiny-mediator.
Shiny Mediator Skill
You are an expert in Shiny Mediator, a mediator pattern library for .NET applications.
When to Use This Skill
Invoke this skill when the user wants to:
- Create request handlers, command handlers, event handlers, or stream handlers
- Generate contracts (IRequest, ICommand, IEvent, IStreamRequest)
- Add middleware (caching, resilience, validation, offline)
- Scaffold ASP.NET, MAUI, or Blazor projects with Shiny Mediator
- Configure Shiny Mediator in their application
- Set up ASP.NET Server-Sent Events (SSE) endpoints with stream handlers
- Use event subscriptions (WaitForSingleEvent, EventStream, Subscribe)
- Generate strongly-typed HTTP clients from OpenAPI/Swagger specs
- Create contract-first HTTP request handlers with [Get], [Post], etc.
- Migrate from MediatR to Shiny Mediator
Library Overview
Documentation: https://shinylib.net/mediator
Shiny Mediator is AOT & trimming friendly, using source generators for automatic DI registration.
Core Patterns
| Pattern | Contract | Handler | Usage | |
|---|---|---|---|---|
| Request | IRequest<TResult> | IRequestHandler<TRequest, TResult> | Queries returning data | |
| Command | ICommand | ICommandHandler<TCommand> | Void state changes | |
| Event | IEvent | IEventHandler<TEvent> | Pub/sub notifications | |
| Stream | IStreamRequest<TResult> | IStreamRequestHandler<TRequest, TResult> | IAsyncEnumerable |
Handler Registration
Always use registration attributes:
Critical: Partial Class Requirement
When using any middleware attribute ([Cache], [OfflineAvailable], [Resilient], [MainThread], [TimerRefresh], [Sample], [Throttle]), the handler class must be declared as `partial`:
This enables the source generator to create the IHandlerAttributeMarker implementation. Without partial, you'll get error SHINY001.
Basic Setup
ASP.NET:
MAUI:
Blazor:
Code Generation Instructions
When generating Shiny Mediator code:
1. Contracts
Always use records for immutability:
2. Handlers
Include all three parameters in Handle method:
3. Middleware Attributes
Apply to handler methods as needed:
[Cache(AbsoluteExpirationSeconds = N)]- Cacheable queries[OfflineAvailable]- Offline storage for mobile[Resilient("policyName")]- Retry/timeout policies[MainThread]- MAUI main thread execution[TimerRefresh(milliseconds)]- Auto-refresh streams[Sample(milliseconds)]- Fixed-window sampling (last event in window executes)[Throttle(milliseconds)]- True throttle (first event executes, cooldown discards rest)[Validate]- Data annotation validation
When using ANY of these attributes, the handler class MUST be `partial`:
4. Middleware Ordering
Use [MiddlewareOrder(int)] on custom middleware classes to control execution order. Lower values run first (outermost). Default is 0.
5. File Organization
Place files in appropriate folders:
- Contracts:
Contracts/{Name}Request.cs,Contracts/{Name}Command.cs - Handlers:
Handlers/{Name}Handler.cs - Middleware:
Middleware/{Name}Middleware.cs
Usage Examples
Request:
Command:
Event:
Chaining via Context:
Event Subscriptions & Streaming
WaitForSingleEvent - Await a single event occurrence (with optional filter):
EventStream - Continuous IAsyncEnumerable stream of events (uses Channels internally):
Subscribe - Manual subscription returning IDisposable:
ASP.NET Server-Sent Events (SSE)
Stream handlers decorated with [MediatorHttpGet] or [MediatorHttpPost] on an IStreamRequestHandler are automatically generated as SSE endpoints by the source generator via MapGeneratedMediatorEndpoints().
Manual SSE endpoint with EventStream:
Stream handler as auto-generated SSE endpoint:
HTTP client-side SSE consumption: Implement IServerSentEventsStream marker on the contract to indicate the server returns SSE format. The generated HTTP handler will use ReadServerSentEvents<T>() to parse the data: prefixed SSE lines.
Contract-First HTTP Clients
Shiny Mediator generates strongly-typed HTTP client handlers from contract classes decorated with HTTP method attributes. No manual HttpClient code needed.
Manual HTTP Contracts
Decorate request classes with [Get], [Post], [Put], [Delete], [Patch] and use [Query], [Header], [Body] on properties:
The source generator creates handler classes inheriting BaseHttpRequestHandler that build routes, add query/header parameters, serialize bodies, and call IHttpClientFactory.
Registration:
OpenAPI Client Generation
Generate contracts, models, and handlers directly from OpenAPI/Swagger specs. Add a <MediatorHttp> item in your .csproj:
Include can be a file path (for local specs) or a logical name when Uri is set separately.
MediatorHttp metadata options:
| Metadata | Description | |
|---|---|---|
Uri | URL or local path to OpenAPI JSON/YAML spec | |
Namespace | C# namespace for generated types | |
ContractPrefix | Prefix for generated contract class names | |
ContractPostfix | Postfix for generated contract class names | |
UseInternalClasses | Generate internal classes instead of public | |
GenerateModelsOnly | Only generate models, no handlers | |
GenerateJsonConverters | Generate JsonConverter implementations for enums |
Registration of generated OpenAPI client:
Then use like any other mediator request:
Best Practices
- Use records for contracts - Immutable, value equality
- One handler per file - Focused and testable
- Appropriate lifetime - Singleton for stateless, Scoped for DbContext
- Use `partial` with middleware attributes - Required for
[Cache],[OfflineAvailable],[Resilient], etc. - Chain via context - Use
context.Request()not injecting IMediator - Implement IContractKey - For custom cache/offline keys
- Always pass CancellationToken - Respect cancellation
- Use IServerSentEventsStream marker - On stream contracts consumed via HTTP SSE
- Stream handlers only support GET/POST - Other HTTP methods are not valid for SSE endpoints
- Use EventStream for SSE push endpoints - Combine
mediator.EventStream<T>()withTypedResults.ServerSentEvents()for event-driven SSE
Reference Files
For detailed templates and examples, see:
reference/templates.md- Code generation templates (includes SSE endpoint templates)reference/scaffolding.md- Project structure templatesreference/middleware.md- Middleware configurationreference/api-reference.md- Full API, event subscriptions, SSE, and NuGet packages
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingProjectTemplates/ShinyAspNet/skills/shiny-mediator/SKILL.md
Popularity
- Repository stars
- 150
- Repository forks
- 14
- 7-day trend score
- 25
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/shinyorg/templates/shiny-mediator)