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 %}}
|
{{% 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]
|
||||||
|
public sealed class CheckoutServiceController : ControllerBase
|
||||||
{
|
{
|
||||||
[ApiController]
|
[HttpPost("/checkout")]
|
||||||
public class CheckoutServiceController : Controller
|
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||||
{
|
{
|
||||||
[HttpPost("/checkout")]
|
Console.WriteLine($"Received Message: {orderId}");
|
||||||
public ActionResult<string> getCheckout([FromBody] int 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 %}}
|
{{% /codetab %}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue