An EventStore client that integrates with Aspire, including health checks, logging, and telemetry.
Install
| Product | Versions |
|---|---|
| .NET |
README
CommunityToolkit.Aspire.EventStore
Registers an EventStoreClient in the DI container for connecting to an EventStore.
Getting started
Prerequisites
- EventStore cluster.
Install the package
Install the .NET Aspire EventStore Client library with NuGet:
dotnet add package CommunityToolkit.Aspire.EventStore
Usage example
In the Program.cs file of your project, call the AddEventStoreClient extension method to register an EventStoreClient for use via the dependency injection container. The method takes a connection name parameter.
builder.AddEventStoreClient("eventstore");
Configuration
The .NET Aspire EventStore 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.AddEventStoreClient():
builder.AddEventStoreClient("eventstore");
And then the connection string will be retrieved from the ConnectionStrings configuration section:
{
"ConnectionStrings": {
"eventstore": "esdb://localhost:22113?tls=false"
}
}
Use configuration providers
The .NET Aspire EventStore Client integration supports Microsoft.Extensions.Configuration. It loads the EventStoreSettings from configuration by using the Aspire:EventStore:Client key. Example appsettings.json that configures some of the options:
{
"Aspire": {
"EventStore": {
"Client": {
"ConnectionString": "esdb://localhost:22113?tls=false",
"DisableHealthChecks": true
}
}
}
}
Use inline delegates
Also you can pass the Action<EventStoreClientSettings> configureSettings delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddEventStoreClient("eventstore", settings => settings.DisableHealthChecks = true);
AppHost extensions
In your AppHost project, install the CommunityToolkit.Aspire.Hosting.EventStore library with NuGet:
dotnet add package CommunityToolkit.Aspire.Hosting.EventStore
Then, in the Program.cs file of AppHost, register EventStore and consume the connection using the following methods:
var eventstore = builder.AddEventStore("eventstore");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(eventstore);
The WithReference method configures a connection in the MyService project named eventstore. In the Program.cs file of MyService, the EventStore connection can be consumed using:
builder.AddEventStoreClient("eventstore");
Then, in your service, inject EventStoreClient and use it to interact with the EventStore API:
public class MyService(EventStoreClient eventStoreClient)
{
// ...
}
Additional documentation
- https://github.com/EventStore/EventStore-Client-Dotnet
- https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-eventstore
Feedback & contributing
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.