aspnet / Announcements

Subscribe to this repo to be notified about major changes in ASP.NET Core and Entity Framework Core
Other
1.66k stars 80 forks source link

[Breaking change]: EndpointName metadata no longer automatically set for minimal endpoints #473

Open captainsafia opened 3 years ago

captainsafia commented 3 years ago

Description

Starting in .NET 6 RC2, behavior that was introduced in .NET 6 RC1 to automatically set the IEndpointNameMetadata for endpoints has been reverted to avoid issues the logic generating duplicate endpoint names.

Version

.NET 6 RC 2

Previous behavior

In .NET 6 RC1 and above, the IEndpointNameMetadata was automatically set for endpoints that referenced a method group. For example, the following code:

app.MapGet("/foo", GetFoo);

Would produce an endpoint for /foo with a EndpointName set to "GetFoo".

New behavior

In .NET 6 RC 2 and onward, the IEndpointNameMetadata is no longer set. For example, the following code:

app.MapGet("/foo", GetFoo);

would not generated any IEndpointNameMetadat.

Type of breaking change

Reason for change

The behavior of automatically setting endpoint name metadata was not robust and resulted in issues where the same name was set for different endpoints. See https://github.com/dotnet/aspnetcore/issues/36487 for more info.

Recommended action

We recommend that developers manually set the IEndpointNameMetadata using the WithName extension method as follows to set the metadata.

app.MapGet("/foo", GetFoo).WithName("GetFoo");

Feature area

ASP.NET Core

Affected APIs

No response