Intent.FastEndpoints.Dispatch.Mediator
Wires FastEndpoints endpoints to dispatch Commands and Queries through Mediator's ISender, so each endpoint 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 EndpointTemplate from Intent.FastEndpoints and extends the result:
EndpointTemplateRegistrationcreates one endpoint per Command or Query that has HTTP settings in the Services designer. FastEndpoints is one class per operation, so endpoints are not grouped by folder.MediatorEndpointExtensionadds aMediator.ISender _senderconstructor parameter (with a null guard) to each of those endpoints and emits the dispatch call inHandleAsync.
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.
For a Command that returns a value, followed by the endpoint's normal response (illustrative):
public class CreateProductCommandEndpoint : Endpoint<CreateProductCommand, Guid>
{
private readonly ISender _sender;
public CreateProductCommandEndpoint(ISender sender)
{
_sender = sender ?? throw new ArgumentNullException(nameof(sender));
}
public override async Task HandleAsync(CreateProductCommand req, CancellationToken ct)
{
var result = Guid.Empty;
result = await _sender.Send(req, ct);
// ... response statement from Intent.FastEndpoints
}
}
For a void Command the call is await _sender.Send(req, ct); with no result. For a Query with no route or query-string parameters (no req), the request is created inline:
result = await _sender.Send(new GetProductsQuery(), ct);
The dispatch statement carries a mediator-dispatch metadata tag so other modules can find it.
One Dispatch Module Per Application
Intent.FastEndpoints.Dispatch.Mediator, Intent.FastEndpoints.Dispatch.Wolverine and Intent.FastEndpoints.Dispatch.MediatR each replace FastEndpoints' EndpointTemplate registration with their own, built from the same Commands and Queries. They are mutually exclusive: install only one of them in an application. Installing more than one makes them compete over the same endpoint files and produces conflicting output.
Prerequisites
Intent.FastEndpoints- generates the endpoint classes this 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.FastEndpoints into an application that already has Intent.Application.Mediator installs this module (the core declares it as interoperability).
Related Modules
- Intent.FastEndpoints - generates the FastEndpoints endpoint classes this module extends.
- Intent.FastEndpoints.Dispatch.Wolverine - the Wolverine equivalent. Mutually exclusive with this module.
Intent.FastEndpoints.Dispatch.MediatR- the MediatR equivalent (no published page). Mutually exclusive with this module.Intent.AspNetCore.Controllers.Dispatch.Mediator- equivalent dispatch wiring for ASP.NET Core controllers (no published page yet).Intent.Application.Mediator- the core module of this family (no published page yet).