Skip to content

Minimal API friendly version of MapWhen #65626

@aelij

Description

@aelij

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When using MapWhen we get a lot of nesting:

app.MapWhen(ctx => ..., appBuilder =>
{
    appBuilder.UseRouting();
    appBuilder.UseEndpoints(routeBuilder => 
    {
         routeBuilder.MapGet(...);
    });
}

app.MapWhen(ctx => ..., appBuilder =>
{
    appBuilder.UseRouting();
    appBuilder.UseCors();
    appBuilder.UseEndpoints(routeBuilder => 
    {
         routeBuilder.MapPost(...);
    });
}

Describe the solution you'd like

It would be nice if we had a top-level API, for example:

var app1 = app.MapBranch(ctx => ...);
app1.UseRouting();
app1.MapGet(...);


var app2 = app.MapBranch(ctx => ...);
app2.UseRouting();
app2.UseCors();
app2.MapPost(...);

MapBranch can return a new type implementing both IApplicationBuilder and IRouteEndpointBuilder.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions