✅ Generic DI in minimal APIs

I want register all the dependencies in one place for the endpoints.

public static void MapAuthEndpoints(this WebApplication app)
{
var auth = app.MapGroup("auth");

auth.MapPost("login",LoginAsync);

auth.MapGet("role/{id:Guid}",GetRoleAsync);
}

private static async Task<ApiResponse> LoginAsync(HttpContext context, LoginRequest loginRequest)
{
var response = await mediator.Send(new LoginCommand(loginRequest));
return new ApiResponse(requestPayload: requestPayload, statusCode: context.Response.StatusCode, response: response);
}

How can i inject IMediator once for all endpoints
Was this page helpful?