Skip to content

Cratis Chronicle connection string configuration

Use AddCratisChronicle to bind the Cratis Chronicle .NET client’s connection string from your host’s configuration. This keeps the endpoint out of application code so you can change servers between environments without changing registration.

Start with the Cratis:Chronicle section in appsettings.json:

appsettings.json:

{
"Cratis": {
"Chronicle": {
"ConnectionString": "chronicle://localhost:35000"
}
}
}

This local address omits credentials from the connection string, but the client still authenticates: it automatically attempts the built-in development credentials. Use explicit credentials for production.

Program.cs:

using Microsoft.Extensions.Hosting;
public static class ConnectionStringsConfigurationRegistration
{
public static void Configure(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.AddCratisChronicle(options => options.EventStore = "my-store");
}
}

View C# snippet source on GitHub

The registration above sets the event store name in code and reads the connection string from Cratis:Chronicle. AddCratisChronicle supports IHostApplicationBuilder for worker and console hosts, and WebApplicationBuilder for ASP.NET Core. Follow Add Chronicle to a worker service or Add Chronicle to an ASP.NET Core app if you still need the host setup.

For these host registrations, the first configured value in this table wins:

Priority Source When it applies
1 configureOptions callback The callback explicitly assigns ConnectionString, overriding the bound section
2 Cratis:Chronicle:ConnectionString The section supplies the connection string; configSection can select another section
3 ConnectionStrings:chronicle Neither the callback nor the section assigns a connection string
4 ChronicleConnectionString.Development No explicit connection string is assigned and the named fallback is absent, empty, or whitespace

The named fallback lets a host use a connection string supplied by Aspire without copying it into Cratis:Chronicle. If the resource has another name, use the overload with connectionStringName to select it. An explicit assignment wins even when you assign ChronicleConnectionString.Development.

This precedence chooses between Chronicle settings. Within a configuration key, the host’s configuration providers decide the value. With the default .NET host setup, command-line arguments override environment variables, which override appsettings.{Environment}.json and appsettings.json. If an endpoint change has no effect, check for a callback assignment before changing another configuration source.

Settings available as both options and connection string keys

Section titled “Settings available as both options and connection string keys”

Some connection settings exist as a ChronicleOptions property and as a connection string key. The client combines them as follows:

Setting Options property Connection string key Combined result
Client certificate path and password Tls:CertificatePath, Tls:CertificatePassword certificatePath, certificatePassword The option wins; the connection string key is used only when the option is not set
CA certificate path Tls:CaCertificatePath caCertificatePath The option wins; the connection string key is used only when the option is not set
Server certificate validation Tls:SkipCertificateValidation skipTlsValidation Validation is on if either setting is explicitly false. Otherwise validation is skipped, also when both are omitted in this release. disableTls=true turns validation off because TLS is not used
Skip compatibility check SkipCompatibilityCheck skipCompatibilityCheck The check is skipped if either is true
Skip keep-alive SkipKeepAlive skipKeepAlive Keep-alive is skipped if either is true, or when serverless mode is on
Serverless mode Serverless:Mode serverless Serverless mode is on if either asks for it
TLS on or off none disableTls Connection string only

Boolean settings that are combined with “either” cannot be switched off from the other source. To turn one off, remove it from both.

Use per-environment files to change the endpoint while keeping the same registration. With the default .NET host setup, appsettings.{Environment}.json overrides matching values in appsettings.json.

appsettings.Development.json:

{
"Cratis": {
"Chronicle": {
"ConnectionString": "chronicle://localhost:35000/?skipTlsValidation=true"
}
}
}

appsettings.Production.json:

{
"Cratis": {
"Chronicle": {
"ConnectionString": "chronicle://clientId:clientSecret@chronicle.production.example.com:35000"
}
}
}

Keep real client secrets out of committed settings files. Supply the production value through your deployment’s secret configuration, and enable server certificate validation as described below.

With the default .NET host setup, an environment variable overrides the connection string in the settings files. .NET maps __ to : in configuration keys, so Cratis:Chronicle:ConnectionString becomes:

Terminal window
export Cratis__Chronicle__ConnectionString="chronicle://clientId:clientSecret@server.example.com:35000"

The .NET client still skips server certificate validation when both settings are omitted in this release. The next major release will enable validation by default. We recommend explicitly adding skipTlsValidation=false to the connection string or setting Cratis:Chronicle:Tls:SkipCertificateValidation=false. First trust the server’s certificate authority (CA), including inside application containers, point caCertificatePath at a file with that CA, or configure a matching certificatePath pin.

Either setting enables validation. A true value in the other setting does not turn it off, so skipTlsValidation=true cannot override Tls:SkipCertificateValidation=false.

A connection constructed with validation skipped logs a startup warning for remote hosts and DNS SRV targets, but not for loopback targets. With disableTls=true, certificate validation does not apply and that warning is suppressed. For development only, use chronicle://localhost:35000?skipTlsValidation=true to explicitly opt out, provided the TLS options do not require validation. Development images generate an untrusted, self-signed certificate on every start, with SANs localhost, chronicle, 127.0.0.1, and ::1. Follow TLS configuration for the trust and pinning requirements.