Modernized .NET example to include modern syntax for controller example and add a minimal API version for completeness

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
This commit is contained in:
Whit Waldo 2025-04-18 18:30:16 -05:00
parent bb573c0a76
commit 2bed589a0e
1 changed files with 18 additions and 10 deletions

View File

@ -119,6 +119,8 @@ Below are code examples that leverage Dapr SDKs to demonstrate an output binding
{{% codetab %}} {{% codetab %}}
The following example demonstrates how to configure an input binding using ASP.NET Core controllers.
```csharp ```csharp
//dependencies //dependencies
using System.Collections.Generic; using System.Collections.Generic;
@ -126,21 +128,27 @@ using System.Threading.Tasks;
using System; using System;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
//code namespace CheckoutService.controller;
namespace CheckoutService.controller
{
[ApiController] [ApiController]
public class CheckoutServiceController : Controller public sealed class CheckoutServiceController : ControllerBase
{ {
[HttpPost("/checkout")] [HttpPost("/checkout")]
public ActionResult<string> getCheckout([FromBody] int orderId) public ActionResult<string> getCheckout([FromBody] int orderId)
{ {
Console.WriteLine("Received Message: " + orderId); Console.WriteLine($"Received Message: {orderId}");
return "CID" + orderId; return $"CID{orderId}";
}
} }
} }
```
The following example demonstrates how to configure the same input binding using a minimal API approach:
```csharp
app.MapPost("checkout", ([FromBody] int orderId) =>
{
Console.WriteLine($"Received Message: {orderId}");
return $"CID{orderId}"
});
``` ```
{{% /codetab %}} {{% /codetab %}}