Skip to content

Connecting to EventSourcingDB

EventSourcingKit talks to EventSourcingDB through a client you register separately, with AddEventSourcingDb. This is where you configure which database to use and how to authenticate, kept apart from EventSourcingKit's own options.

Registering the Client

Call AddEventSourcingDb before AddEventSourcingKit, because the event store depends on the client:

using EventSourcingDb.DependencyInjection;

builder.Services.AddEventSourcingDb(builder.Configuration);

The client reads its configuration from the EventSourcingDb section:

{
  "EventSourcingDb": {
    "BaseUrl": "http://localhost:3000",
    "ApiToken": "secret"
  }
}

Both settings are required:

Option Type Purpose
BaseUrl string The base URL of your EventSourcingDB instance, for example http://localhost:3000.
ApiToken string The API token EventSourcingDB was started with, sent with every request.

These are exactly the values you chose when running EventSourcingDB.

Configuring in Code

Like EventSourcingKit, the client accepts an optional delegate to adjust the options after binding, which is handy for resolving secrets at runtime:

builder.Services.AddEventSourcingDb(
    builder.Configuration,
    options => options.ApiToken = ResolveToken()
);

For More Information