aspnet / Announcements

Subscribe to this repo to be notified about major changes in ASP.NET Core and Entity Framework Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Breaking change]: IEndpointMetadataProvider and IEndpointParameterMetadataProvider interface changes in 7.0 RC2

halter73 opened this issue · comments

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 dotnet/aspnetcore#43125 (comment) for an API diff.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
  • Behavioral change: Existing code and binaries may experience different run-time behavior.

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

  • Parameters changed: Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider.PopulateMetadata
  • Parameters changed: Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider.PopulateMetadata
  • Removed: Microsoft.AspNetCore.Http.Metadata.EndpointMetadataContext
  • Removed: Microsoft.AspNetCore.Http.Metadata.EndpointParameterMetadataContext