Events
Events are immutable facts that describe what happened in your system. Chronicle identifies events by their event type rather than the .NET CLR type, which makes the CLR type a convenient vessel for expressing intent and structure.
using Cratis.Chronicle.Events;
[EventType]public record EventsIndexEmployeeRegistered(string FirstName, string LastName);import { eventType } from '@cratis/chronicle';
@eventType()class EventsIndexEmployeeRegistered { constructor( readonly firstName: string, readonly lastName: string ) {}}Event Sequences and the Event Log
Section titled “Event Sequences and the Event Log”Events live in event sequences, which are ordered, append-only streams. Each event receives a monotonically increasing sequence number that makes it possible to replay events, resume processing, and reason about how far consumers have progressed.
Chronicle includes a specialized event sequence called the event log. It is the default sequence used throughout the system and is exposed through the IEventLog API.
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;
public class EventsIndexEmployeesService(IEventLog eventLog){ public Task RegisterEmployee(EventSourceId employeeId, string firstName, string lastName) => eventLog.Append(employeeId, new EventsIndexEmployeeRegistered(firstName, lastName));}import { IEventStore } from '@cratis/chronicle';
class EventsIndexEmployeesService { constructor(private readonly store: IEventStore) {}
async registerEmployee(employeeId: string, firstName: string, lastName: string): Promise<void> { await this.store.eventLog.append(employeeId, new EventsIndexEmployeeRegistered(firstName, lastName)); }}Working with Events
Section titled “Working with Events”Use these topics to append, read, and manage events: