-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add remarks to FromBodyAttrbiute #56997
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
Conversation
@@ -9,6 +9,9 @@ namespace Microsoft.AspNetCore.Mvc; | |||
/// <summary> | |||
/// Specifies that a parameter or property should be bound using the request body. | |||
/// </summary> | |||
/// <remarks> | |||
/// Be default ASP.NET Core runtime delegates the responsibility of reading the body to an input formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true for MVC but not for minimal API, which also uses the same attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it behave for minipal API then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it just reads the form itself directly before passing control to the user's endpoint method using https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.features.iformfeature.readformasync (I haven't dug through the code to check, but that's what I see to remember from doing work on the binding "glue" stuff).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martincostello , I changed the wording.
[[FromBody] attrbiute](https://learn.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-8.0#frombody-attribute) section contains a very important comment : > The ASP.NET Core runtime delegates the responsibility of reading the body to an input formatter. This is quite an important detail to capture it in the xmldoc of this attribute.
Co-authored-by: Martin Costello <martin@martincostello.com>
What exactly is "an input formatter"? |
@KennethHoff ,is it a hint that link to the description of formatters concept is missing or a real question? If it's the latter one , then |
Both, really 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Out of curiousity, what motiviated you to add this note? It seems like you might not have expected input formatters to be coming in to play here?
@captainsafia , well, I knew this, but I've learned it the hard way by making wrong assumptions. And minimal API behavior was a surprise. |
@captainsafia , actually, there are many places where xmldocs are lacking important details. Sometimes, clarifications can be found in docs at Microsoft.Learn. But quite often I need to look into sources. For exception handler middleware it is not mentioned that by default 404 status code without started response will cause I do not get the description for this overload. I'd also change the wording of the comment for adding a custom exception handler from "it is used by exception handler middleware" to "it is required to use exception handler middleware for the custom handler to work. (Analyzer would be even better;-) ) For authentication it's not obvious when Why is Or another example:
Does it mean |
Add remarks to FromBodyAttrbiute
Summary of the changes (Less than 80 chars)
Description
[FromBody] attrbiute section of the docs dedicated to Model Binding contains a very important statement:
This is quite an important detail (gotcha, actually) to capture it in the xmldoc of the attribute, so it's imediately visible in IDE.