Skip to content

Aspire Integration

Chronicle provides first-class support for Microsoft Aspire, making it straightforward to run Chronicle as part of an Aspire distributed application. The Cratis.Chronicle.Aspire package adds a Chronicle resource to your Aspire AppHost, handling container lifecycle, endpoint wiring, and MongoDB configuration automatically.

Add the Cratis.Chronicle.Aspire package to your AppHost project:

Terminal window
dotnet add package Cratis.Chronicle.Aspire

For local development, call AddCratisChronicle() without arguments. This uses the Chronicle development image (cratis/chronicle:latest-development), which bundles MongoDB, so no external database is required.

var chronicle = builder.AddCratisChronicle();

The development image is ideal for:

  • Getting started quickly without additional infrastructure
  • Running in CI pipelines where a full stack is needed

For production or staging environments, use the configure callback. This switches to the production image (cratis/chronicle:latest) and lets you wire up an external database resource.

var mongo = builder.AddConnectionString("chronicle-mongo");
var chronicle = builder.AddCratisChronicle(chronicle =>
chronicle.WithMongoDB(mongo));

The WithMongoDB method sets the Cratis__Chronicle__Storage__Type and Cratis__Chronicle__Storage__ConnectionDetails environment variables on the Chronicle container using the connection string from the provided MongoDB resource.

mongo can be any IResourceBuilder<IResourceWithConnectionString>, including:

  • A MongoDB Atlas connection string (builder.AddConnectionString("..."))
  • A Mongo container added directly in the AppHost: builder.AddMongoDB("mongo")
  • Any self-hosted or cloud MongoDB resource
var postgres = builder.AddConnectionString("chronicle-postgres");
var chronicle = builder.AddCratisChronicle(chronicle =>
chronicle.WithPostgreSql(postgres));

postgres can be any IResourceBuilder<IResourceWithConnectionString>, including:

  • A connection string (builder.AddConnectionString("..."))
  • A PostgreSQL container: builder.AddPostgres("postgres").AddDatabase("chronicle")
var sql = builder.AddConnectionString("chronicle-sql");
var chronicle = builder.AddCratisChronicle(chronicle =>
chronicle.WithMsSql(sql));

sql can be any IResourceBuilder<IResourceWithConnectionString>, including:

  • A connection string (builder.AddConnectionString("..."))
  • A SQL Server container: builder.AddSqlServer("sql").AddDatabase("chronicle")

For SQLite, provide the connection string directly (SQLite is file-based and does not require a network resource):

var chronicle = builder.AddCratisChronicle(chronicle =>
chronicle.WithSqlite("Data Source=/data/chronicle.db"));

Pass the Chronicle resource as a connection string reference to your application projects so they receive the correct endpoint at runtime:

var api = builder.AddProject<Projects.MyApi>("api")
.WithReference(chronicle);

The connection string exposed by ChronicleResource uses the chronicle:// scheme and points to the gRPC port (35000 by default), matching the format expected by ChronicleOptions.FromConnectionString().

Chronicle exposes the following ports:

PortEndpoint NameDescription
35000grpcPrimary Chronicle gRPC service
8080managementManagement API, Workbench, and health checks

Both endpoints are registered automatically when you call AddCratisChronicle().

A typical Aspire AppHost Program.cs for a production setup with MongoDB:

var builder = DistributedApplication.CreateBuilder(args);
var mongo = builder.AddConnectionString("chronicle-mongo");
var chronicle = builder.AddCratisChronicle(chronicle =>
chronicle.WithMongoDB(mongo));
builder.AddProject<Projects.MyApi>("api")
.WithReference(chronicle);
builder.Build().Run();

For development, simplify further by dropping the MongoDB wiring:

var builder = DistributedApplication.CreateBuilder(args);
var chronicle = builder.AddCratisChronicle();
builder.AddProject<Projects.MyApi>("api")
.WithReference(chronicle);
builder.Build().Run();
Image tagDescription
cratis/chronicle:latestProduction image — no embedded MongoDB
cratis/chronicle:latest-developmentDevelopment image — includes embedded MongoDB
cratis/chronicle:latest-development-slimDevelopment slim image — no embedded MongoDB

See Production Hosting for guidance on running Chronicle in production environments.