mediator-reference
fullstackhero/dotnet-starter-kit/.agents/skills/mediator-reference/SKILL.md
CQRS interface reference for FSH. This project uses the Mediator source generator, NOT MediatR. Reference when implementing commands, queries, and handlers.
Skill6.8k starsChanged 9 days ago
What's in it
- Mediator Reference
- Interfaces
- Pattern
- Registration — the four places
- Common errors
---
name: mediator-reference
description: CQRS interface reference for FSH. This project uses the Mediator source generator, NOT MediatR. Reference when implementing commands, queries, and handlers.
user-invocable: false
---
# Mediator Reference
⚠️ **FSH uses the `Mediator` source-generator package (`using Mediator;`), NOT `MediatR`.** Different
interfaces — MediatR types won't compile. The CQRS interfaces below are the library's own (no FSH wrapper).
## Interfaces
| Purpose | ✅ Mediator (use) | ❌ MediatR (don't) |
|---|---|---|
| Command | `ICommand<TResponse>` | `IRequest<TResponse>` |
| Query | `IQuery<TResponse>` | `IRequest<TResponse>` |
| Command handler | `ICommandHandler<TCommand, TResponse>` | `IRequestHandler<…>` |
| Query handler | `IQueryHandler<TQuery, TResponse>` | `IRequestHandler<…>` |
| Notification / domain event | `INotification` (`IDomainEvent : INotification`) | `INotification` |
## Pattern
```csharp
// Command/Query → the Contracts project (Modules.{X}.Contracts/v1/{Area}/)
public sealed record Create{Entity}Command(string Name) : ICommand<Guid>;
// Handler → the runtime project (Modules.{X}/Features/v1/{Area}/{Feature}/), public sealed
public sealed class Create{Entity}CommandHandler({X}DbContext db)
: ICommandHandler<Create{Entity}Command, Guid>
{
public async ValueTask<Guid> Handle(Create{Entity}Command command, CancellationToken cancellationToken)
{
// …
}
}
```
Rules: handlers return **`ValueTask<T>`** (not `Task<T>`); parameter named `command`/`query` (not `request`);
`public sealed`; `.ConfigureAwait(false)` on awaits. Send via `mediator.Send(command, ct)` (the `IMediator`
interface name matches MediatR's — that part is fine).
## Registration — the four places
The source generator only scans assemblies listed in `o.Assemblies`, and that list exists in **two host
files**. A new module needs **two markers** (a Contracts type **and** the module type) added to the Mediator
list **plus** an entry in the `moduleAssemblies` array — in **both** `FSH.Starter.Api/Program.cs` **and**
`FSH.Starter.DbMigrator/Program.cs`:
```csharp
builder.Services.AddMediator(o =>
{
o.ServiceLifetime = ServiceLifetime.Scoped;
o.Assemblies = [
/* … */
typeof(FSH.Modules.{X}.Contracts.{X}ContractsMarker), // Contracts assembly
typeof(FSH.Modules.{X}.{X}Module)]; // runtime assembly
});
```
See `add-module` for the full procedure.
## Common errors
| Symptom | Cause → fix |
|---|---|
| `IRequest<T>` / `IRequestHandler<,>` not found | MediatR interface → use `ICommand`/`IQuery` + `ICommandHandler`/`IQueryHandler` |
| `Task<T>` vs `ValueTask<T>` mismatch | Handler must return `ValueTask<T>` |
| Handler not invoked at runtime | Assembly missing from `o.Assemblies` (in one or both Program.cs files) |
More agent context in fullstackhero/dotnet-starter-kit
12 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
Skill
- add-entity.agents/skills/add-entity/SKILL.md
- add-feature.agents/skills/add-feature/SKILL.md
- add-full-slice.agents/skills/add-full-slice/SKILL.md
- add-integration-event.agents/skills/add-integration-event/SKILL.md
- add-module.agents/skills/add-module/SKILL.md
- add-permission.agents/skills/add-permission/SKILL.md
- add-react-page.agents/skills/add-react-page/SKILL.md
- create-migration.agents/skills/create-migration/SKILL.md
- query-patterns.agents/skills/query-patterns/SKILL.md
- testing-guide.agents/skills/testing-guide/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

