Skip to content

Chronicle .NET client configuration

Configure the Chronicle .NET client to choose which kernel and event store your application uses. Client settings control the connection and client behavior; they do not configure the kernel’s ports, storage, or server-side limits. Those belong in Hosting Configuration.

This section covers .NET host configuration and direct ChronicleClient construction. The appsettings.json binding and AddCratisChronicle registration shown here are .NET APIs, not a shared configuration contract for every Chronicle client. See Where the clients differ for client-specific workflows.

With the standard .NET host defaults, put bindable settings under Cratis:Chronicle in appsettings.json. Environment variables override file values; for example, Cratis__Chronicle__EventStore maps to Cratis:Chronicle:EventStore. If you customize the host’s configuration providers, their order determines precedence.

The configureOptions callback on AddCratisChronicle runs after configuration binding, so values it sets override bound values. Custom providers and resolvers are different: supply those objects through the separate configure callback described in Structural Dependencies.

Start with the kernel endpoint and the event store your application will use:

{
"Cratis": {
"Chronicle": {
"ConnectionString": "chronicle://localhost:35000",
"EventStore": "my-store"
}
}
}

Register the client on the host with AddCratisChronicle. It reads the section above; the example’s configureOptions callback then selects my-store explicitly:

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

View C# snippet source on GitHub

Use IHostApplicationBuilder for worker and console hosts, or WebApplicationBuilder for ASP.NET Core. Once registered, application services can resolve IEventStore through dependency injection.

The connection string above uses TLS, but the client skips server certificate validation by default. Before connecting beyond a trusted development environment, configure certificate trust and enable TLS validation. See the getting-started host guides for the surrounding application setup.

First run a development kernel reachable at localhost:35000. Client registration does not start a kernel. Install Cratis.Chronicle.AspNetCore for a web application, or Cratis.Chronicle for a worker or console application.

No connection or event store settings are needed for a local hosted application. The connection defaults to localhost:35000 with the built-in development credentials. The hosted event store name is derived from ProgramIdentifier, or the entry assembly name when that identifier is unset; see EventStore for normalization and overrides.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
public static class MinimalChronicleWebApplication
{
public static async Task Run(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.AddCratisChronicle();
builder.Services.Configure<ChronicleAspNetCoreOptions>(options => options.UseAutomaticMiddleware = false);
var app = builder.Build();
app.UseRouting();
app.UseCratisChronicle();
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready")
});
await app.RunAsync();
}
}

View C# snippet source on GitHub

UseCratisChronicle() installs the middleware; place it after routing, authentication and authorization when those are present. The example disables automatic middleware so that this explicit placement takes effect. Namespace selection defaults to the caller-controlled x-cratis-tenant-id header: use a trusted proxy or a resolver derived from authenticated identity before accepting untrusted traffic.

using Microsoft.Extensions.Hosting;
public static class MinimalChronicleWorker
{
public static async Task Run(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.AddCratisChronicle();
using var host = builder.Build();
await host.RunAsync();
}
}

View C# snippet source on GitHub

public static class MinimalChronicleConsole
{
public static async Task Run()
{
using var client = new ChronicleClient();
var eventStore = await client.GetEventStore("my-store");
await eventStore.Connection.Connect();
}
}

View C# snippet source on GitHub

Direct construction also accepts no arguments, but does not bind host configuration or derive an event store name. Supply the name to GetEventStore; that call can wait for the connection and registration.

Hosted applications eagerly connect in the background after ApplicationStarted, with or without UseCratisChronicle(). A pending kernel connection does not hold up host startup. Failures are logged by the shared startup service; they do not stop the host. Options validation still runs at startup, and logging a connection failure is not proof that the client recovered. Host shutdown cancels the startup wait, not necessarily the underlying transport operation.

ASP.NET Core automatically registers the Chronicle health check with chronicle and ready tags, not a liveness tag. The web example maps /health/ready; it stays unhealthy until the connection and required artifact registration succeed. A running host is not necessarily ready to serve Chronicle-dependent requests. Workers must expose their own readiness signal if required.

Configure an explicit kernel endpoint and application credentials from a secret provider, enable server certificate validation, and trust the kernel’s certificate authority. The default skips server certificate validation and is not a production security configuration. Set an explicit event store name when multiple applications must share a store or deployments must keep the same name despite assembly renames.

Kernel storage, TLS, encryption and bootstrap clients are separate server requirements, not client options. See Production hosting for conditional requirements and Settings that must match the kernel for the client/kernel pairs.

  • ChronicleOptions Reference lists the settings available to direct clients and hosted applications.
  • Connection Strings explains endpoint selection and credentials.
  • Namespaces shows how to select an event store namespace per request for multi-tenancy.
  • Camel Casing configures serialized property names, projection mappings, and read model container names.
  • gRPC Message Size helps you fit large messages within both client and kernel limits.
  • Structural Dependencies supplies custom artifact discovery, identity providers, and namespace resolvers.
  • Settings that must match the kernel lists the client and kernel settings that have to agree.
  • TLS explains how to enable server certificate validation and configure certificate handling.

Register event types and other artifacts in code when you want to declare them where the application is assembled, or when their assemblies cannot carry Chronicle markers. Explicit declarations merge with marker-based discovery; they do not override conflicting identities.

using Cratis.Chronicle;
using Cratis.Chronicle.Events.Constraints;
namespace ExplicitCompositionExample
{
public record OrderPlaced(decimal Total);
public record OrderTotal(decimal Total);
public class TotalReducer
{
public OrderTotal Reduce(OrderPlaced @event, OrderTotal? current) =>
new((current?.Total ?? 0m) + @event.Total);
}
public class OrderNotifier
{
public void On(OrderPlaced @event) => Console.WriteLine($"Order total: {@event.Total}");
}
public class OneOrderPerSource
{
public void Define(IConstraintBuilder builder) => builder.Unique<OrderPlaced>();
}
public class Customers;
public static class Composition
{
public static ChronicleOptions CreateOptions()
{
var options = new ChronicleOptions();
options.ExplicitArtifacts
.RegisterEventType<OrderPlaced>(_ => _.WithId("order-placed").Public())
.RegisterReactor<OrderNotifier>("order-notifier")
.RegisterReducer<TotalReducer>("order-total")
.RegisterConstraint<OneOrderPerSource>()
.RegisterEventSource<Customers>("customers");
return options;
}
}
}

View C# snippet source on GitHub

Configure these declarations before creating stores. Each store captures an immutable snapshot; later option edits do not alter existing stores or their reconnect registrations. Continue to the .NET API reference for registration rules and custom-provider compatibility.

When a type is registered with an explicit alias, use the store’s registry to obtain its event identity before constructing a concurrency scope. The alias belongs to that store’s registration and may differ from the type’s attributes:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences.Concurrency;
namespace ExplicitConcurrencyExample
{
public record OrderPlaced(decimal Total);
public static class Scope
{
public static ConcurrencyScope ForOrder(IEventStore store, EventSourceId source)
{
var eventType = store.EventTypes.GetEventTypeFor(typeof(OrderPlaced));
return new ConcurrencyScopeBuilder()
.WithEventSourceId(source)
.WithEventType(eventType)
.Build();
}
}
}

View C# snippet source on GitHub

The scope uses the registered ID and generation, including the alias. Type-based and generic declaration helpers still use marker-based identities. See Event concurrency when applying an expected sequence number to an append.

If your next task is to change storage, listeners, or kernel features, continue to Hosting Configuration. If you do not yet have a kernel to connect to, start with Run Chronicle locally.