Skip to content

Improve minimal api routing with grouping #36007

Closed
@ziaulhasanhamim

Description

@ziaulhasanhamim

Background and Motivation

The new minimal approach in asp.net core 6 is good. I mean it's great. But I don't this will be useful in a real web application. Because this doesn't have an easy way to integrate route grouping. With route grouping, minimal actions can be separated into multiple files easily with the help of normal or static(since c# doesn't support modules like f#) classes without using MVC or Razor pages.

Proposed API

namespace Microsoft.AspNetCore.Builder;

+ public class RouteGroup : IApplicationBuilder, IEndpointRouteBuilder
+ {
+     // Needed members to implement those interfaces
+ }

public class MinimalActionEndpointRouteBuilderExtensions
{
+     public static void IncludeRouteGroup(this IEndpointRouteBuilder endpoints, string pattern, RouteGroup routeGroup);
}

Usage Examples

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

RouteGroup usersRoutes = new();
usersRoutes.MapGet("{id}", (int id) => GetUserById(id));

app.IncludeRouteGroup("/api/users/", usersRoutes);

You can separate these route actions to multiple files easily. RouteGroup would become more useful if in the future c# gets support for top-level functions(not just for Program.cs).

Metadata

Metadata

Assignees

Labels

Priority:0Work that we can't release withoutapi-approvedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions