Skip to content

Latest commit

 

History

History
115 lines (77 loc) · 3.33 KB

File metadata and controls

115 lines (77 loc) · 3.33 KB

CommunityToolkit.Aspire.KurrentDB

Registers an KurrentDBClient in the DI container for connecting to KurrentDB.

Getting started

Prerequisites

  • KurrentDB cluster.

Install the package

Install the Aspire KurrentDB Client library with NuGet:

dotnet add package CommunityToolkit.Aspire.KurrentDB

Usage example

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");

Configuration

The Aspire KurrentDB Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.

Use a connection string

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"
    }
}

Use configuration providers

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
      }
    }
  }
}

Use inline delegates

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);

AppHost extensions

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)
{
    // ...
}

Additional documentation

Feedback & contributing

https://github.com/CommunityToolkit/Aspire