Mediator Pattern
Decouple request senders from handlers. First-class support for CQRS with commands, queries, pipeline behaviors, pre/post-processors and auto-registration.
Learn more
Lightweight & composable. Zero boilerplate.
CQRS & MediatorDecorator PatternChain of ResponsibilityPublish / Subscribe
Get started
Each package is fully independent โ install only the patterns your project uses.
dotnet add package Forma.Mediatordotnet add package Forma.Decoratordotnet add package Forma.Chainsdotnet add package Forma.PubSub.InMemoryIn action
Define a request, write a handler โ Forma wires everything through the DI container. No base classes, no magic strings, no reflection surprises.
Explore all patterns โ// 1. Define the query
public record GetProductQuery(int Id)
: IRequest<Product>;
// 2. Implement the handler
public class GetProductHandler
: IRequestHandler<GetProductQuery, Product>
{
public Task<Product> Handle(
GetProductQuery q, CancellationToken ct)
=> _repo.FindAsync(q.Id, ct);
}
// 3. Register once, call anywhere
builder.Services.AddFormaMediator(
typeof(Program).Assembly);
var product = await sender.Send(
new GetProductQuery(42));