Get started with the .NET client
Use the .NET client when you want direct typed access to Chronicle from a C# application. The smallest useful loop is:
- create a
ChronicleClient - open an event store
- append a fact to an event log
- let projections, reducers, and reactors observe that fact
Connect
Section titled “Connect”For local development, start the Chronicle kernel and connect with the development connection string.
using Cratis.Chronicle;
using var client = new ChronicleClient(ChronicleConnectionString.Development);var eventStore = await client.GetEventStore("Quickstart");ChronicleConnectionString.Development points at the default local Chronicle kernel with development credentials. Use ChronicleConnectionString.Default or an explicit new ChronicleConnectionString("chronicle://...") when connecting to another environment.
Define an event
Section titled “Define an event”Events are immutable facts. In .NET, mark event records with [EventType] so Chronicle can discover and register their schema.
using Cratis.Chronicle.Events;
[EventType]public record BookAdded(string Title, string Isbn);Append the event
Section titled “Append the event”Append the event against the event source it belongs to. The event source id is not part of the event payload; Chronicle stores it in the event context.
var bookId = "book-123";
var result = await eventStore.EventLog.Append( bookId, new BookAdded("The Pragmatic Programmer", "978-0135957059"));
if (!result.IsSuccess){ // Decide whether to retry or surface the append failure to the caller.}After the append succeeds, Chronicle persists the event and forwards it to the projections, reducers, reactors, and subscriptions that observe the event sequence.
Use a host integration
Section titled “Use a host integration”For ASP.NET Core and Worker Service applications, prefer the host integration instead of creating the client manually:
builder.Services.AddCratisChronicle(options => options.EventStore = "Quickstart");The host integration registers the event store, event log, read models, projections, reducers, reactors, constraints, and related services in dependency injection.