Example use:
builder.Services.AddMediatR(...);
...
app.MapGet<GetFruit.Request, GetFruit.Response>("/getFruit");
app.MapPost<CreateFruit.Request, CreateFruit.Response>("/createFruit");
app.MapPost<DeleteFruit.Request>("/deleteFruit");
Assuming there exist MediatR handlers:
public sealed class GetFruit: IRequestHandler<GetFruit.Request, GetFruit.Response?>
{
public async Task<Response?> Handle(Request request, CancellationToken cancellationToken)
{
...
return new Response(...);
}
public sealed record Request(Guid Id) : IRequest<Response>;
public sealed record Response(...);
}
public sealed class CreateFruit: IRequestHandler<CreateFruit.Request, CreateFruit.Response>
{
public async Task<Response> Handle(Request request, CancellationToken cancellationToken)
{
...
return new Response(...);
}
public sealed record Request(...) : IRequest<Response>;
public sealed record Response(Guid Id);
}
public sealed class DeleteFruit: IRequestHandler<DeleteFruit.Request>
{
public async Task Handle(Request request, CancellationToken cancellationToken)
{
...
}
public sealed record Request(Guid Id) : IRequest;
}