Перейти к содержимому

KurrentDB Client integration reference

Это содержимое пока не доступно на вашем языке.

⭐ Community Toolkit KurrentDB logo

To get started with the Aspire KurrentDB integrations, follow the Get started with KurrentDB integrations guide.

This article includes full details about the Aspire KurrentDB Client integration.

To install the 📦 CommunityToolkit.Aspire.KurrentDB NuGet package in the client-consuming project:

.NET CLI — Add CommunityToolkit.Aspire.KurrentDB package
dotnet add package CommunityToolkit.Aspire.KurrentDB

In the Program.cs file of your client-consuming project, call the AddKurrentDBClient extension to register a KurrentDBClient for use via the dependency injection container.

C# — Program.cs
builder.AddKurrentDBClient(connectionName: "kurrentdb");

You can then retrieve the KurrentDBClient instance using dependency injection. For example, to retrieve the client from a service:

C# — ExampleService.cs
public class ExampleService(KurrentDBClient client)
{
// Use client...
}

There might be situations where you want to register multiple KurrentDBClient instances with different connection names. To register keyed KurrentDB clients, call the AddKeyedKurrentDBClient method:

C# — Program.cs
builder.AddKeyedKurrentDBClient(name: "events");
builder.AddKeyedKurrentDBClient(name: "audit");

Then retrieve the instances using dependency injection:

C# — ExampleService.cs
public class ExampleService(
[FromKeyedServices("events")] KurrentDBClient eventsClient,
[FromKeyedServices("audit")] KurrentDBClient auditClient)
{
// Use clients...
}

For more information on keyed services, see .NET dependency injection: Keyed services.

The KurrentDB client integration provides multiple configuration approaches and options to meet 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 AddKurrentDBClient:

C# — Program.cs
builder.AddKurrentDBClient("kurrentdb");

Then the connection string will be retrieved from the ConnectionStrings configuration section:

JSON — appsettings.json
{
"ConnectionStrings": {
"kurrentdb": "kurrentdb://localhost:22113?tls=false"
}
}

The KurrentDB client integration supports Microsoft.Extensions.Configuration. It loads the KurrentDBSettings from configuration using the Aspire:KurrentDB:Client key. Example appsettings.json:

JSON — appsettings.json
{
"Aspire": {
"KurrentDB": {
"Client": {
"ConnectionString": "kurrentdb://localhost:22113?tls=false",
"DisableHealthChecks": false,
"DisableTracing": false
}
}
}
}

You can pass the delegate to set up options inline:

C# — Program.cs
builder.AddKurrentDBClient(
"kurrentdb",
static settings => settings.DisableHealthChecks = true);

By default, Aspire integrations enable health checks for all services. The KurrentDB integration adds a health check that verifies the KurrentDB instance is reachable and can execute commands.

The KurrentDB integration uses the following log categories:

  • Aspire.KurrentDB

The KurrentDB integration emits tracing activities using OpenTelemetry when tracing is not disabled.