Intent.AspNetCore.Controllers.Dispatch.Mediator
Wires ASP.NET Core controllers to dispatch Commands and Queries through Mediator's ISender, so each controller action hands its request to the handler generated by Intent.Application.Mediator.
What This Module Does
The module has no templates of its own. It replaces the registration of the ControllerTemplate from Intent.AspNetCore.Controllers for CQRS elements and extends the result:
ImplicitControllerTemplateRegistrationgroups every Command and Query that has HTTP settings by its parent folder in the Services designer and creates one controller for each group. Elements directly in the package root go into aDefaultcontroller.MediatorControllerDispatchExtensionadds aMediator.ISender _senderconstructor parameter (with a null guard) to each of those controllers and emits the dispatch call in every action. It also registers the Mediator command and query contracts as type sources for the controller.
Generated Dispatch
The request is sent with ISender.Send. The response type is inferred from the Command or Query contract, so there is no type argument:
var result = await _sender.Send(command, cancellationToken); // returns a value
await _sender.Send(command, cancellationToken); // void command
When the action has no body payload, the request is built from the route and query parameters, with constructor syntax if the Command or Query has a parameterised constructor and object-initialiser syntax otherwise:
new GetProductByIdQuery(id: id)
new GetProductByIdQuery { Id = id }
The extension also generates, before the dispatch:
- parameter-to-payload assignments, so a route or query value populates a matching property of a body payload when that property was left at its default;
- a
BadRequest()guard when a route value and the same property on the body payload disagree; - the stream handling for file upload operations.
The action then ends with the return statement Intent.AspNetCore.Controllers generates for the operation.
One Dispatch Module Per Application
Intent.AspNetCore.Controllers.Dispatch.Mediator, Intent.AspNetCore.Controllers.Dispatch.Wolverine and Intent.AspNetCore.Controllers.Dispatch.MediatR each register the controller template for the same Commands and Queries. Install only one of them in an application.
Prerequisites
Intent.AspNetCore.Controllers- owns theControllerTemplatethis module extends.Intent.Application.Mediator- generates the Commands, Queries and handlers, and brings in theMediatorlibrary that providesISender.Intent.Modelers.Services.CQRS- the Command and Query designer elements.
Installing Intent.AspNetCore.Controllers into an application that already has Intent.Application.Mediator installs this module (the core declares it as interoperability).
Related Modules
- Intent.AspNetCore.Controllers - owns the controller template this module extends.
- Intent.AspNetCore.Controllers.Dispatch.Wolverine - the Wolverine equivalent.
Intent.AspNetCore.Controllers.Dispatch.MediatR- the MediatR equivalent (no published page).Intent.FastEndpoints.Dispatch.Mediator- equivalent dispatch wiring for FastEndpoints (no published page yet).Intent.Application.Mediator- the core module of this family (no published page yet).