Skip to content

Commit f7ec6fb

Browse files
committed
Scope to parameter binding attributes.
1 parent 159a831 commit f7ec6fb

File tree

6 files changed

+65
-30
lines changed

6 files changed

+65
-30
lines changed

src/Mvc/Mvc.Core/src/FromBodyAttribute.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@ namespace Microsoft.AspNetCore.Mvc;
1010
/// Specifies that a parameter or property should be bound using the request body.
1111
/// </summary>
1212
/// <remarks>
13+
/// Binds a parameter or property to the request body.
14+
///
1315
/// By default, ASP.NET Core MVC delegates the responsibility of reading the body to an input formatter.<br/>
1416
/// In the case of ASP.NET Core Minimal APIs, the body is deserialized by <see cref="System.Text.Json.JsonSerializer"/>.
17+
///
18+
/// For more information about parameter binding see
19+
/// <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding?">Parameter binding</see>.
1520
/// </remarks>
21+
/// <example>
22+
/// In this example, the value of the 'name' field in the form-data request body is bound to the name parameter,
23+
/// and the value of the 'age' field is bound to the age parameter.
24+
/// <code>
25+
/// app.MapPost("/from-body", ([FromBody] Person person) => person);
26+
/// </code>
27+
/// </example>
1628
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
1729
public class FromBodyAttribute : Attribute, IBindingSourceMetadata, IConfigureEmptyBodyBehavior, IFromBodyMetadata
1830
{

src/Mvc/Mvc.Core/src/FromFormAttribute.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ namespace Microsoft.AspNetCore.Mvc;
99
/// <summary>
1010
/// Specifies that a parameter or property should be bound using form-data in the request body.
1111
/// </summary>
12+
/// <remarks>
13+
/// Binds a parameter or property to a field in a form-data request body with the same name,
14+
/// or the name specified in the <see cref="Name"/> property.
15+
/// Form parameter names are matched case-insensitively.
16+
///
17+
/// For more information about parameter binding see
18+
/// <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding?">Parameter binding</see>.
19+
/// </remarks>
20+
/// <example>
21+
/// In this example, the value of the 'name' field in the form-data request body is bound to the name parameter,
22+
/// and the value of the 'age' field is bound to the age parameter.
23+
/// <code>
24+
/// app.MapPost("/from-form", ([FromForm] string name, [FromForm] int age)
25+
/// => new { Name = name, Age = age });
26+
/// </code>
27+
/// </example>
1228
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
1329
public class FromFormAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider, IFromFormMetadata
1430
{

src/Mvc/Mvc.Core/src/FromHeaderAttribute.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ namespace Microsoft.AspNetCore.Mvc;
1010
/// Specifies that a parameter or property should be bound using the request headers.
1111
/// </summary>
1212
/// <remarks>
13-
/// When placed on a parameter, the parameter will be bound to the value of the request header with the same name.
14-
/// Use the <see cref="Name"/> property to specify a different header name.
13+
/// Binds a parameter or property to the value of the request header with the same name,
14+
/// or the name specified in the <see cref="Name"/> property.
15+
/// Note that HTTP header names are case-insensitive, so the header name is matched without regard to case.
16+
///
17+
/// For more information about parameter binding see
18+
/// <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding?">Parameter binding</see>.
1519
/// </remarks>
1620
/// <example>
1721
/// In this example, the value of the 'User-Agent' header is bound to the parameter.
1822
/// <code>
19-
/// [HttpGet]
20-
/// public string GetUserAgent([FromHeader("User-Agent")] string userAgent)
23+
/// app.MapGet("/user-agent", ([FromHeader(Name = "User-Agent")] string userAgent)
24+
/// => userAgent);
2125
/// </code>
22-
/// Note that HTTP header names are case-insensitive, so the header name is matched without regard to case.
2326
/// </example>
2427
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
2528
public class FromHeaderAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider, IFromHeaderMetadata

src/Mvc/Mvc.Core/src/FromQueryAttribute.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ namespace Microsoft.AspNetCore.Mvc;
99
/// <summary>
1010
/// Specifies that a parameter or property should be bound using the request query string.
1111
/// </summary>
12+
/// <remarks>
13+
/// Binds a parameter or property to the value of query string parameter with the same name,
14+
/// or the name specified in the <see cref="Name"/> property.
15+
/// The query parameter name is matched case-insensitively.
16+
///
17+
/// For more information about parameter binding see
18+
/// <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding?">Parameter binding</see>.
19+
/// </remarks>
20+
/// <example>
21+
/// In this example, the value of the 'User-Agent' header is bound to the parameter.
22+
/// <code>
23+
/// app.MapGet("/version", ([FromQuery(Name = "api-version")] string apiVersion)
24+
/// => apiVersion);
25+
/// </code>
26+
/// </example>
1227
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
1328
public class FromQueryAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider, IFromQueryMetadata
1429
{

src/Mvc/Mvc.Core/src/FromRouteAttribute.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ namespace Microsoft.AspNetCore.Mvc;
1010
/// <summary>
1111
/// Specifies that a parameter or property should be bound using route-data from the current request.
1212
/// </summary>
13+
/// <remarks>
14+
/// Binds a parameter or property to the value of a route parameter with the same name,
15+
/// or the name specified in the <see cref="Name"/> property.
16+
/// The route parameter name is matched against parameter segments of the route pattern case-insensitively.
17+
///
18+
/// For more information about parameter binding see
19+
/// <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding?">Parameter binding</see>.
20+
/// </remarks>
21+
/// <example>
22+
/// In this example, the value of the 'id' route parameter is bound to the parameter.
23+
/// <code>
24+
/// app.MapGet("/from-route/{id}", ([FromRoute] string id) => id);
25+
/// </code>
26+
/// </example>
1327
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
1428
public class FromRouteAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider, IFromRouteMetadata
1529
{

src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,6 @@ namespace Microsoft.AspNetCore.Mvc;
1111
/// <summary>
1212
/// A filter that specifies the type of the value and status code returned by the action.
1313
/// </summary>
14-
/// <remarks>
15-
/// This attribute can be used to specify the type of the response body, the status code,
16-
/// and content-type(s) of the response.
17-
///
18-
/// In an MVC application, this attribute can be applied to an action method or controller class.
19-
/// In a Minimal API application, this attribute should be applied to the delegate method.
20-
///
21-
/// More than one instance of ProducesResponseTypeAttribute with different status codes may
22-
/// be used to specify multiple possible responses from an endpoint.
23-
/// </remarks>
24-
/// <example>
25-
/// In the following example, the ProducesResponseTypeAttribute is used to specify the type of the
26-
/// response body and the status code for the successful response and the status code, type, and content
27-
/// type for the error response.
28-
/// <code>
29-
/// app.MapGet("/todos/{id}",
30-
/// [ProducesResponseType(typeof(Todo), StatusCodes.Status200OK)]
31-
/// [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound, "application/problem+json")]
32-
/// async (TodoDb db, string id) =>
33-
/// await db.Todos.FindAsync(id)
34-
/// is Todo todo
35-
/// ? Results.Ok(todo)
36-
/// : Results.NotFound());
37-
/// </code>
38-
/// </example>
3914
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
4015
public class ProducesResponseTypeAttribute : Attribute, IApiResponseMetadataProvider
4116
{

0 commit comments

Comments
 (0)