mediator-reference

Implement FSH Mediator CQRS interfaces, ValueTask handlers, and assembly registrations.

6.7k|2.0k|Updated Aug 20, 2021
One-click install
npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill mediator-reference
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mediator-reference
Source: https://github.com/fullstackhero/dotnet-starter-kit/tree/main/.agents/skills/mediator-reference
Command: npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill mediator-reference

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents compile-time and runtime errors caused by confusing FSH’s Mediator source-generator CQRS interfaces with MediatR, and it clarifies the exact handler/registration contracts you must follow.

Core Features & Use Cases

  • Use the correct CQRS interfaces: Commands and queries use ICommand<TResponse> / IQuery<TResponse> and handlers use ICommandHandler<,> / IQueryHandler<,> (not MediatR’s IRequest<> patterns).
  • Implement handlers correctly: Handler methods must return ValueTask<T> and follow the expected parameter naming conventions and coding style.
  • Register new modules in the Mediator scan lists: Ensures the source generator scans the right Contracts and runtime assemblies by updating both required host Program entry points.
  • Common error diagnosis: Explains typical symptoms (missing interfaces, wrong Task vs ValueTask, handlers not being invoked) and maps them to fixes.

Quick Start

Use the mediator-reference skill as your checklist when adding a new module so your command/query contracts, handler signatures, and Mediator assembly registration match FSH’s source-generator expectations.

Frequently Asked Questions about mediator-reference

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement CQRS command and query handlers using FSH's Mediator source generator?

FSH CQRS handlers use `ICommandHandler<,>` and `IQueryHandler<,>` interfaces with methods returning `ValueTask<T>`, replacing standard MediatR `IRequest` patterns. You must define contracts using `ICommand<TResponse>` and `IQuery<TResponse>`.

Why are my FSH Mediator handlers not being invoked at runtime?

Handlers are not invoked when module assemblies are missing from the generator scan lists. You must update both the API and DbMigrator host Program entry points to register the required Contracts and runtime assemblies.

What is the difference between FSH Mediator interfaces and MediatR IRequest patterns?

FSH Mediator uses `ICommand<T>` and `IQuery<T>` contracts with `ValueTask`-based handlers, whereas MediatR uses `IRequest<>` patterns. Mixing these interfaces causes compile-time and runtime errors.

Do I need to return ValueTask or Task for FSH Mediator command handlers?

FSH Mediator command and query handlers must return `ValueTask<T>`. Returning a standard `Task<T>` violates the source generator's expected handler signatures and causes compile-time errors.

How do I register a new module for Mediator source generator scanning in FSH?

To register a new module for Mediator scanning, update the assembly scan lists in both the API and DbMigrator host Program entry points to ensure the source generator discovers your Contracts and runtime assemblies.

How do I fix missing interface errors when creating FSH CQRS contracts?

Missing interface errors occur when using MediatR's `IRequest` instead of FSH's `ICommand<TResponse>` or `IQuery<TResponse>`. Update your command and query contracts to use the correct FSH Mediator interfaces to resolve this.