Chronicle migrations with explicit registration
Explicit migration registration in Cratis Chronicle lets you keep event contracts free of client attributes and declare their generation relationship in application setup. Use it when the composition root, where you configure the application, owns event identities instead of the event records themselves.
Register the generations and recipe
Section titled “Register the generations and recipe”Start with a Chronicle-enabled .NET application and the record types for both generations. Follow the kernel rollout and backfill guidance before registering a new generation in an existing event store.
Register both records with the same stable event type id and adjacent generation numbers, then nominate one migration recipe. In this example, Previous.OldName becomes Current.NewName without adding attributes to either record:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Events.Migrations;
namespace ExplicitMigrationExample{ public record Previous(string OldName); public record Current(string NewName);
public class PlainRename { public void Upcast(IEventMigrationBuilder<Current, Previous> builder) => builder.Properties(_ => _.RenamedFrom(current => current.NewName, previous => previous.OldName));
public void Downcast(IEventMigrationBuilder<Previous, Current> builder) => builder.Properties(_ => _.RenamedFrom(previous => previous.OldName, current => current.NewName)); }
public class TypedRename(IEventTypes eventTypes) : EventTypeMigration<Current, Previous>(eventTypes) { public override void Upcast(IEventMigrationBuilder<Current, Previous> builder) => builder.Properties(_ => _.RenamedFrom(current => current.NewName, previous => previous.OldName));
public override void Downcast(IEventMigrationBuilder<Previous, Current> builder) => builder.Properties(_ => _.RenamedFrom(previous => previous.OldName, current => current.NewName)); }
public static class Composition { public static ChronicleOptions CreateOptions() { var options = new ChronicleOptions(); options.ExplicitArtifacts .RegisterEventType<Previous>(_ => _.WithId("person-registered").Generation(1)) .RegisterEventType<Current>(_ => _.WithId("person-registered").Generation(2)) .RegisterMigration<PlainRename>(); // Register TypedRename instead to use the registry-taking base constructor. return options; } }}RegisterMigration<PlainRename>() selects the plain recipe: a class whose Upcast and Downcast methods declare the transformation in each direction. Registering the recipe does not register Previous or Current for you; the two RegisterEventType calls supply those identities.
The example also shows TypedRename as an alternative. It uses the same builders but derives from EventTypeMigration<Current, Previous> and passes IEventTypes to the base constructor. Chronicle supplies the owning store’s finalized event registry so the base class can resolve the explicitly registered identities. Register TypedRename instead of PlainRename if you prefer this form. Registering both would give two recipes for the same transition and is rejected.
Both forms produce declarative definitions for the kernel. Explicit registration changes how the client selects the recipe, not multi-version storage or backfill.
Preparation and validation
Section titled “Preparation and validation”Chronicle validates every explicitly nominated recipe before applying registration effects, even if discovery would not otherwise select it. A plain recipe needs public, synchronous instance methods with the exact typed builders shown above. Static methods, async void methods, overloads and ambiguous roles are rejected.
An existing typed migration that uses the parameterless base constructor still resolves its endpoints from the types’ declarations. Nominating that class does not switch its constructor behavior. For identities supplied by explicit registration, use the registry-taking constructor or the plain recipe form.
Before deployment, check that both endpoints are registered, their ids match, their generations are adjacent, and only one recipe owns the transition. For exact method signatures, custom-provider compatibility and activation limits, continue with the .NET API reference.