[FEATURE] Consider using FastEnpoints over Minimal API
Would greatly simplify the endpoint registration boilerplate (e.g. https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/App/Vertical.Slice.Template/Products/Features/CreatingProduct/v1/CreateProductEndpoint.cs). It's also built on top of minimal APIs and has built in support for other tools e.g. FluentValidation.
public class MyEndpoint : Endpoint<MyRequest, MyResponse>
{
private ISender _mediator;
public MyEndpoint(ISender mediator)
{
_mediator = mediator;
}
public override void Configure()
{
Post("/api/user/create");
AllowAnonymous();
}
public override async Task HandleAsync(MyRequest req, CancellationToken ct)
{
Response = await _mediator.Send(req, ct);
}
public class Handler(ISomeService someService) : IRequestHandler<MyRequest, MyResponse>
{
public async Task<MyResponse> Handle(MyRequest request, CancellationToken ct)
{
// Do stuff
return new MyResponse();
}
}
}
This is a contrived example of course as you could have your validation in here, mappings etc.
Counter point, the MediatR author has mentioned that there's no need to use both libraries (as covered here) which I don't personally agree with given the MediatR pipeline gives you a middleware that works with any .NET project eg Razor, Console, Azure Funcs, Lambdas etc. and has always been the most useful part of the library IMO.