© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
33 replies
OneDeveloper

✅ 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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Unit Testing in Minimal Apis
C#CC# / help
11mo ago
minimal api DI magic
C#CC# / help
2y ago
Eagerly compile minimal apis
C#CC# / help
2y ago
❔ WebApplicationFactory and Minimal-APIs
C#CC# / help
3y ago