Intent.AspNetCore.Controllers.Dispatch.MediatR module instructs ASP.NET Core Controllers to dispatch Commands and Queries to separate handlers via MediatR, implementing the CQRS pattern in your Web API.
Overview
This module bridges ASP.NET Core Controllers with the MediatR library, enabling a clean separation between your HTTP layer and application logic. Controllers become thin dispatchers that forward requests to specialized command and query handlers.Architecture
The module implements a clean CQRS architecture:What Gets Generated
Controller with MediatR Dispatch
Controllers are generated with MediatR injection:Key Features
CQRS Pattern
Separates read and write operations using Commands and Queries
Thin Controllers
Controllers focus on HTTP concerns, not business logic
MediatR Integration
Leverages MediatR’s request/response pipeline
Pipeline Behaviors
Supports validation, logging, and other cross-cutting concerns
Commands vs Queries
Commands
Commands represent write operations that modify state:Queries
Queries represent read operations that don’t modify state:Benefits
Separation of Concerns
Controller Responsibilities
Controller Responsibilities
- HTTP request/response handling
- Route configuration
- Parameter binding
- Status code determination
Handler Responsibilities
Handler Responsibilities
- Business logic
- Data access
- Domain operations
- Validation
Testability
Handlers can be tested independently of HTTP concerns:Pipeline Behaviors
MediatR supports pipeline behaviors for cross-cutting concerns:Validation Behavior
Logging Behavior
Services Designer Configuration
In the Services Designer, operations are automatically mapped to Commands or Queries:Installation
The module is automatically installed when you have both:Dependencies
Intent.Application.MediatR(>= 4.3.0)Intent.AspNetCore.Controllers(>= 7.1.0)Intent.Modelers.Services.CQRS
Next Steps
MediatR Behaviors
Add validation, logging, and other pipeline behaviors
CQRS
Generate CQRS handlers automatically
FluentValidation
Add request validation
Controllers
Learn more about controller generation
