dotnet / aspnetcore Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve endpoint metadata debugging by overriding ToString #39792
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Thanks for contacting us. We're moving this issue to the |
Where does this show up to the user or when debugging? |
endpoints.MapGet("/", c =>
{
var endpoint = c.GetEndpoint();
var metadata = endpoint.Metadata; // view all metadata
var nameMetadata = metadata.GetMetadata<EndpointNameMetadata>(); // view one metadata
} |
API review: API approved. We're happy to consider using ToString instead of alternate ways such as interface implementation. We do not guarantee that the returned string would be consistent across releases. We should try and make the strings appear similar without dictating a serialization format. Legibility is the primary motive here. |
Background and Motivation
It is useful to understand what behavior endpoint metadata is adding to an endpoint. A human-readable summary of metadata would make this much easier. It can be viewed when debugging, and in logs when metadata is logged.
#34604 is another potential use of human-readable endpoint metadata.
Proposed API
I propose overriding ToString on metadata types. See changes in #35231 and #39753 as examples.
Alternative Designs
An alternative approach is to add an interface to get display information:
I don't think this adds anything. We already have ToString that is pretty much for this situation.
DebuggerDisplayAttribute
is not appropriate because there are situations where it is useful to get the debug value at runtime. e.g. logging. It is only useful if we provide debug text using something other than ToString.Risks
Someone uses endpoint metadata ToString to drive application behavior, and we change the ToString value. I don't think this is a valid concern. Someone could depend on text in exception messages and logging, and those change from time to time.
The text was updated successfully, but these errors were encountered: