Skip to content

ModelEndpointDataSource not idempotent #29146

@yang-er

Description

@yang-er

Describe the bug

ModelEndpointDataSource.Endpoints.getter is not idempotent.

Since DefaultEndpointConventionBuilder.Build() doesn't use another copy / clone of the original EndpointBuilder, if the _conventions is not empty, the convention will be applied one more time. Something like endpointConventionBuilder.WithMetadata(new HttpMethodMetadata(new[] { "GET" })) will add the repeated metadata object into that EndpointBuilder, and the metadata collection of last built endpoint will grow larger.

The following scenarios will make the convention collection non-empty:

  • endpoints.MapMethods/MapGet/MapPost/MapPut/MapFallback/...
  • endpoints.Map(...).WithMetadata(...)

A new endpoint will be created when

  • Use reflection and read IOptions<RouteOptions>.Value.EndpointDataSources.SelectMany(a => a.Endpoints)
  • The change token of ActionEndpointDataSourceBase is notified (which will take the last built endpoint to Match)

Maybe we should make DefaultEndpointConventionBuilder.Build() idempotent or the result of ModelEndpointDataSource.Endpoints cached.

Further technical details

  • ASP.NET Core version 3.0, 3.1, 5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-routinginvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions