Skip to content

Commit

Permalink
Merge pull request #1142 from WhitWaldo/quickstart-bindings-dotnet-2
Browse files Browse the repository at this point in the history
Update Dapr Bindings Quickstart - .NET
  • Loading branch information
paulyuk authored Jan 23, 2025
2 parents bd483b2 + deed0b9 commit 3928177
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bindings/csharp/sdk/batch/batch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.14.*-*" />
<PackageReference Include="Dapr.AspNetCore" Version="1.15.0-rc02" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions bindings/csharp/sdk/batch/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ limitations under the License.
options.SupportedCultures = [invariantCulture];
});

builder.Services.AddDaprClient();

var app = builder.Build();

if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

app.UseRequestLocalization();

// Triggered by Dapr input binding
app.MapPost("/" + cronBindingName, async () =>
app.MapPost("/" + cronBindingName, async (DaprClient client) =>
{
Console.WriteLine("Processing batch..");

string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
using var client = new DaprClientBuilder().Build();
foreach (Order ord in ordersArray?.orders ?? new Order[] { })
{
var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});";
Expand All @@ -65,5 +66,5 @@ limitations under the License.

await app.RunAsync();

public record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
public record Orders([property: JsonPropertyName("orders")] Order[] orders);
public sealed record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
public sealed record Orders([property: JsonPropertyName("orders")] Order[] orders);

0 comments on commit 3928177

Please sign in to comment.