Can a single ASP.NET Core project use both controllers and minimal APIs simultaneously, and what are valid reasons to do so?
Short answer
Yes -- app.MapControllers() and individual app.MapGet/MapPost calls can coexist in the same Program.cs without conflict, as long as their route patterns don't overlap ambiguously.
Advertisement
AModel answer
Yes -- app.MapControllers() and individual app.MapGet/MapPost calls can coexist in the same Program.cs without conflict, as long as their route patterns don't overlap ambiguously. Valid reasons include incrementally migrating a controller-based application to minimal APIs feature-by-feature, or using minimal APIs specifically for a small number of simple, high-throughput endpoints while keeping complex, filter-heavy business logic on controllers within the same overall application.
var app = builder.Build();
app.MapControllers(); // existing, complex business logic endpoints
app.MapGet("/health", () => Results.Ok("healthy")); // simple, high-frequency endpoint as minimal API
app.MapGet("/version", () => Results.Ok(new { version = "1.4.2" }));Real-world example
A large e-commerce API keeps its complex order-processing logic on controllers (benefiting from the filter pipeline) while adding new, simple, frequently-polled health and status endpoints as minimal APIs for their lower overhead.
Likely follow-ups
- What routing conflicts can arise when mixing both approaches in the same URL space?
- Is this hybrid approach considered a maintainability risk long-term?
Related topics