Advertisement
Intermediate ASP.NET Core, Controllers vs Minimal APIs

How do you organize a large number of minimal API endpoints without ending up with an enormous, unwieldy Program.cs file?

Short answer

Common patterns include extension methods grouping related endpoint registrations (e.g., MapProductEndpoints(this WebApplication app)) called once from Program.cs, or the newer RouteGroupBuilder (via app.MapGroup("/products")) letting you apply shared prefixes, filters, and…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Common patterns include extension methods grouping related endpoint registrations (e.g., MapProductEndpoints(this WebApplication app)) called once from Program.cs, or the newer RouteGroupBuilder (via app.MapGroup("/products")) letting you apply shared prefixes, filters, and metadata to a cohesive group of related endpoints defined in a separate file -- both approaches keep Program.cs concise while maintaining minimal API's lightweight style.
// ProductEndpoints.cs
public static class ProductEndpoints {
    public static void MapProductEndpoints(this WebApplication app) {
        var group = app.MapGroup("/api/products").RequireAuthorization();
        group.MapGet("/", GetAll);
        group.MapGet("/{id}", GetById);
        group.MapPost("/", Create);
    }
}

// Program.cs
app.MapProductEndpoints();
Real-world example
A minimal-API-based project with 60+ endpoints organizes them into a dozen feature-specific extension method files (MapProductEndpoints, MapOrderEndpoints, etc.), keeping Program.cs to a handful of clean, readable registration calls.
Likely follow-ups
  • How does MapGroup let you apply shared authorization or filters to an entire group at once?
  • What naming/organizational conventions work best for large minimal API codebases?
Related topics