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]: IEndpointMetadataProvider and IEndpointParameterMetadataProvider interface changes in 7.0 RC2 #496

Open halter73 opened 2 years ago

halter73 commented 2 years ago

Description

In ASP.NET Core 7 RC2, the IEndpointMetadataProvider and IEndpointParameterMetadataProvider interfaces introduced in preview 4 have been updated to take an EndpointBuilder rather than a EndpointMetadataContext or EndpointParameterMetadataContext.

Version

.NET 7 RC 2

Previous behavior

The PopulateMetadata methods on both interfaces took their respective context arguments as a single parameter. Both contexts included services (IServiceProvider) and endpoint metadata (IList<object>).

EndpointMetadataContext included the MethodInfo for the minimal route handler MVC action that took the implementing type as a parameter or returned it. EndpointParameterMetadataContext provided ParameterInfo and could only be used on parameter types.

New behavior

Now in RC2, both interfaces' PopulateMetadata method take an EndpointBuilder as their second parameter. The EndpointBuilder provides access to the application services (IServiceProvider) and endpoint metadata (IList<object>) previously provided by EndpointMetadataContext and EndpointParameterMetadataContext.

Now, IEndpointMetadataProvider takes a MethodInfo and IEndpointParameterMetadataProvider takes a ParameterInfo as their first parameter.

Both EndpointMetadataContext and EndpointParameterMetadataContext have been removed.

See https://github.com/dotnet/aspnetcore/issues/43125#issuecomment-1218534849 for an API diff.

Type of breaking change

Reason for change

The metadata providers now get access to more metadata like the RoutePattern (with a downcast) and DisplayName via the EndpointBuilder, and this allowed us to delete unnecessary context types.

Recommended action

Update implementations of IEndpointMetadataProvider and IEndpointParameterMetadataProvider to access the information necessary from the new parameters. There should be nothing that was available via the contexts previously that are unavailable via PopulateMetadata's new parameters.

Affected APIs