Skip to content

Commit 95d559d

Browse files
committed
Moved to parameter-binding
1 parent f7d6411 commit 95d559d

8 files changed

Lines changed: 111 additions & 80 deletions

File tree

aspnetcore/fundamentals/minimal-apis/includes/parameter-binding10.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,33 @@ The rules for determining a binding source from a parameter:
396396
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
397397
1. The parameter is from the body.
398398

399+
### Custom parameter binding with `IBindableFromHttpContext`
400+
401+
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
402+
403+
```csharp
404+
public interface IBindableFromHttpContext<TSelf>
405+
where TSelf : class, IBindableFromHttpContext<TSelf>
406+
{
407+
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
408+
}
409+
```
410+
411+
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
412+
413+
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
414+
415+
The following is an example implementation of a custom parameter that binds from an HTTP header:
416+
417+
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/CustomBoundParameters.cs":::
418+
419+
You can also implement validation within your custom binding logic:
420+
421+
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
422+
423+
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/10.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
424+
425+
399426
### Configure JSON deserialization options for body binding
400427

401428
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.

aspnetcore/fundamentals/minimal-apis/includes/parameter-binding7.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,33 @@ The rules for determining a binding source from a parameter:
322322
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
323323
1. The parameter is from the body.
324324

325+
### Custom parameter binding with `IBindableFromHttpContext`
326+
327+
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
328+
329+
```csharp
330+
public interface IBindableFromHttpContext<TSelf>
331+
where TSelf : class, IBindableFromHttpContext<TSelf>
332+
{
333+
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
334+
}
335+
```
336+
337+
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
338+
339+
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
340+
341+
The following is an example implementation of a custom parameter that binds from an HTTP header:
342+
343+
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/CustomBindingExample/CustomBoundParameter.cs":::
344+
345+
You can also implement validation within your custom binding logic:
346+
347+
:::code language="csharp" source="~/fundamentals/minimal-apis/7.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
348+
349+
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/7.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
350+
351+
325352
### Configure JSON deserialization options for body binding
326353

327354
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.

aspnetcore/fundamentals/minimal-apis/includes/parameter-binding8.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,33 @@ The rules for determining a binding source from a parameter:
396396
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
397397
1. The parameter is from the body.
398398

399+
### Custom parameter binding with `IBindableFromHttpContext`
400+
401+
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
402+
403+
```csharp
404+
public interface IBindableFromHttpContext<TSelf>
405+
where TSelf : class, IBindableFromHttpContext<TSelf>
406+
{
407+
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
408+
}
409+
```
410+
411+
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
412+
413+
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
414+
415+
The following is an example implementation of a custom parameter that binds from an HTTP header:
416+
417+
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/CustomBoundParameter.cs":::
418+
419+
You can also implement validation within your custom binding logic:
420+
421+
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
422+
423+
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/8.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
424+
425+
399426
### Configure JSON deserialization options for body binding
400427

401428
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.

aspnetcore/fundamentals/minimal-apis/includes/parameter-binding9.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,32 @@ The rules for determining a binding source from a parameter:
396396
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
397397
1. The parameter is from the body.
398398

399+
### Custom parameter binding with `IBindableFromHttpContext`
400+
401+
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
402+
403+
```csharp
404+
public interface IBindableFromHttpContext<TSelf>
405+
where TSelf : class, IBindableFromHttpContext<TSelf>
406+
{
407+
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
408+
}
409+
```
410+
411+
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
412+
413+
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
414+
415+
The following is an example implementation of a custom parameter that binds from an HTTP header:
416+
417+
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/CustomBoundParameters.cs":::
418+
419+
You can also implement validation within your custom binding logic:
420+
421+
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
422+
423+
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/9.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
424+
399425
### Configure JSON deserialization options for body binding
400426

401427
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.

aspnetcore/fundamentals/minimal-apis/includes/responses7-8.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: tdykstra
33
ms.author: tdykstra
4-
ms.date: 08/26/2025
4+
ms.date: 08/07/2024
55
---
66

77
:::moniker range=">= aspnetcore-7.0 <= aspnetcore-8.0"
@@ -229,31 +229,6 @@ public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
229229
builder.Metadata.Add(new ProducesAttribute(MediaTypeNames.Text.Html));
230230
}
231231
```
232-
## Custom parameter binding with `IBindableFromHttpContext`
233-
234-
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
235-
236-
```csharp
237-
public interface IBindableFromHttpContext<TSelf>
238-
where TSelf : class, IBindableFromHttpContext<TSelf>
239-
{
240-
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
241-
}
242-
```
243-
244-
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
245-
246-
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
247-
248-
The following is an example implementation of a custom parameter that binds from an HTTP header:
249-
250-
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/CustomBoundParameters.cs":::
251-
252-
You can also implement validation within your custom binding logic:
253-
254-
:::code language="csharp" source="~/fundamentals/minimal-apis/8.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
255-
256-
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/8.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
257232

258233
## Configure JSON serialization options
259234

aspnetcore/fundamentals/minimal-apis/includes/responses9.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,32 +223,6 @@ An alternative approach is using the <xref:Microsoft.AspNetCore.Mvc.ProducesAttr
223223

224224
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/Snippets/Program.cs" id="snippet_11":::
225225

226-
## Custom parameter binding with `IBindableFromHttpContext`
227-
228-
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
229-
230-
```csharp
231-
public interface IBindableFromHttpContext<TSelf>
232-
where TSelf : class, IBindableFromHttpContext<TSelf>
233-
{
234-
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
235-
}
236-
```
237-
238-
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
239-
240-
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
241-
242-
The following is an example implementation of a custom parameter that binds from an HTTP header:
243-
244-
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/CustomBoundParameters.cs":::
245-
246-
You can also implement validation within your custom binding logic:
247-
248-
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
249-
250-
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/9.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
251-
252226
## Configure JSON serialization options
253227

254228
By default, minimal API apps use [`Web defaults`](/dotnet/standard/serialization/system-text-json-configure-options#web-defaults-for-jsonserializeroptions) options during JSON serialization and deserialization.

aspnetcore/fundamentals/minimal-apis/parameter-binding.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ author: wadepickett
44
description: Learn how parameters are populated before invoking minimal route handlers.
55
ms.author: wpickett
66
monikerRange: '>= aspnetcore-7.0'
7-
ms.date: 07/09/2025
7+
ms.date: 09/02/2025
88
uid: fundamentals/minimal-apis/parameter-binding
9+
ai-usage: ai-assisted
910
---
1011

1112
# Parameter Binding in Minimal API apps

aspnetcore/fundamentals/minimal-apis/responses.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: brunolins16
44
description: Learn how to create responses for minimal APIs in ASP.NET Core.
55
ms.author: brolivei
66
monikerRange: '>= aspnetcore-7.0'
7-
ms.date: 08/26/2025
7+
ms.date: 08/22/2025
88
uid: fundamentals/minimal-apis/responses
99
ai-usage: ai-assisted
1010
---
@@ -268,32 +268,6 @@ An alternative approach is using the <xref:Microsoft.AspNetCore.Mvc.ProducesAttr
268268

269269
:::code language="csharp" source="~/fundamentals/minimal-apis/9.0-samples/Snippets/Program.cs" id="snippet_11":::
270270

271-
## Custom parameter binding with `IBindableFromHttpContext`
272-
273-
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
274-
275-
```csharp
276-
public interface IBindableFromHttpContext<TSelf>
277-
where TSelf : class, IBindableFromHttpContext<TSelf>
278-
{
279-
static abstract ValueTask<TSelf?> BindAsync(HttpContext context, ParameterInfo parameter);
280-
}
281-
```
282-
283-
By implementing the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601>, you can create custom types that handle their own binding logic from the HttpContext. When a route handler includes a parameter of this type, the framework automatically calls the static BindAsync method to create the instance:
284-
285-
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/Program.cs" id="snippet_IBindableFromHttpContext":::
286-
287-
The following is an example implementation of a custom parameter that binds from an HTTP header:
288-
289-
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/CustomBoundParameters.cs":::
290-
291-
You can also implement validation within your custom binding logic:
292-
293-
:::code language="csharp" source="~/fundamentals/minimal-apis/10.0-samples/CustomBindingExample/Program.cs" id="snippet_Validation":::
294-
295-
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/10.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
296-
297271
## Configure JSON serialization options
298272

299273
By default, minimal API apps use [`Web defaults`](/dotnet/standard/serialization/system-text-json-configure-options#web-defaults-for-jsonserializeroptions) options during JSON serialization and deserialization.

0 commit comments

Comments
 (0)