dotnet / dotnet/aspnetcore

Minimal API friendly version of `MapWhen`

Open
#65,626 0 comments 2 reactions 0 assignees View on GitHub
api-proposal api-suggestion area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] 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:

```cs
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:

```cs
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.