Adding dotnet code snippet for saving and retrieving mulitple states (#2280)

Signed-off-by: Will Velida <willvelida@microsoft.com>
This commit is contained in:
Will Velida 2022-03-22 16:04:59 +13:00 committed by GitHub
parent fa1d0a8eac
commit 938b29005b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 1 deletions

View File

@ -529,7 +529,36 @@ Try getting state again and note that no value is returned.
Below are code examples that leverage Dapr SDKs for saving and retrieving multiple states.
{{< tabs Java Python Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
{{< tabs Dotnet Java Python Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
{{% codetab %}}
```csharp
//dependencies
using Dapr.Client;
//code
namespace EventService
{
class Program
{
static async Task Main(string[] args)
{
string DAPR_STORE_NAME = "statestore";
//Using Dapr SDK to retrieve multiple states
using var client = new DaprClientBuilder().Build();
IReadOnlyList<BulkStateItem> mulitpleStateResult = await client.GetBulkStateAsync(DAPR_STORE_NAME, new List<string> { "order_1", "order_2" }, parallelism: 1);
}
}
}
```
Navigate to the directory containing the above code, then run the following command to launch a Dapr sidecar and run the application:
```bash
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 dotnet run
```
{{% /codetab %}}
{{% codetab %}}