In order to use Dapr with C#, you just have to create a new ASP.NET Core Web API Project and reference the Nuget package Dapr.AspNetCore Once done, just go in the Program.cs and chain the method AddDapr() after the method AddControllers(): builder.Services.AddControllers().AddDapr();
In addition to that, just call these methods to register the Pub\Sub building block:
app.MapSubscribeHandler();
app.UseCloudEvents();
At this point, you can inject the DaprClient, in your controller or services, to interact with the several APIs of Dapr.
public CustomersController(DaprClient daprClient)
{
this.daprClient = daprClient;
}
We then can run the application along with Dapr sidecar using...