Commands and Handlers with MediatR
Dispatch requests to dedicated handlers.
Registering MediatR
MediatR scans your assemblies to discover handlers. Register it once at startup, pointing it at an assembly that contains your handlers.
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));IRequest
A message that expects a response implements IRequest<TResponse>. The type parameter is what the handler returns.
public record CreateOrderCommand(int CustomerId, string[] Items)
: IRequest<int>; // returns the new order idAll lessons in this course
- CQRS Concepts
- Commands and Handlers with MediatR
- Pipeline Behaviors
- Notifications and Events