mirror of https://github.com/dapr/docs.git
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:
parent
bb573c0a76
commit
2bed589a0e
|
|
@ -119,6 +119,8 @@ Below are code examples that leverage Dapr SDKs to demonstrate an output binding
|
|||
|
||||
{{% codetab %}}
|
||||
|
||||
The following example demonstrates how to configure an input binding using ASP.NET Core controllers.
|
||||
|
||||
```csharp
|
||||
//dependencies
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -126,21 +128,27 @@ using System.Threading.Tasks;
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
//code
|
||||
namespace CheckoutService.controller
|
||||
namespace CheckoutService.controller;
|
||||
|
||||
[ApiController]
|
||||
public sealed class CheckoutServiceController : ControllerBase
|
||||
{
|
||||
[ApiController]
|
||||
public class CheckoutServiceController : Controller
|
||||
[HttpPost("/checkout")]
|
||||
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||
{
|
||||
[HttpPost("/checkout")]
|
||||
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||
{
|
||||
Console.WriteLine("Received Message: " + orderId);
|
||||
return "CID" + orderId;
|
||||
}
|
||||
Console.WriteLine($"Received Message: {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 %}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue