Registers an KurrentDBClient in the DI container for connecting to KurrentDB.
- KurrentDB cluster.
Install the Aspire KurrentDB Client library with NuGet:
dotnet add package CommunityToolkit.Aspire.KurrentDB
In the Program.cs file of your project, call the AddKurrentDBClient extension method to register an KurrentDBClient for use via the dependency injection container. The method takes a connection name parameter.
builder.AddKurrentDBClient("kurrentdb");The Aspire KurrentDB Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.
When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string when calling builder.AddKurrentDBClient():
builder.AddKurrentDBClient("kurrentdb");And then the connection string will be retrieved from the ConnectionStrings configuration section:
{
"ConnectionStrings": {
"kurrentdb": "kurrentdb://localhost:22113?tls=false"
}
}The Aspire KurrentDB Client integration supports Microsoft.Extensions.Configuration. It loads the KurrentDBSettings from configuration by using the Aspire:KurrentDB:Client key. Example appsettings.json that configures some of the options:
{
"Aspire": {
"KurrentDB": {
"Client": {
"ConnectionString": "kurrentdb://localhost:22113?tls=false",
"DisableHealthChecks": true
}
}
}
}Also you can pass the Action<KurrentDBSettings> configureSettings delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddKurrentDBClient("kurrentdb", settings => settings.DisableHealthChecks = true);In your AppHost project, install the CommunityToolkit.Aspire.Hosting.KurrentDB library with NuGet:
dotnet add package CommunityToolkit.Aspire.Hosting.KurrentDB
Then, in the Program.cs file of AppHost, register KurrentDB and consume the connection using the following methods:
var kurrentdb = builder.AddKurrentDB("kurrentdb");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(kurrentdb);The WithReference method configures a connection in the MyService project named kurrentdb. In the Program.cs file of MyService, the KurrentDB connection can be consumed using:
builder.AddKurrentDBClient("kurrentdb");Then, in your service, inject KurrentDBClient and use it to interact with the KurrentDB API:
public class MyService(KurrentDBClient client)
{
// ...
}