Chronicle camel case naming configuration
Configure camel case naming in the Chronicle .NET client when your stored event and read model properties need names such as firstName instead of FirstName. The same policy controls projection property mappings and read model container names.
Overview
Section titled “Overview”By default, the .NET client preserves C# property names. CamelCaseNamingPolicy converts those names to camelCase during serialization and projection definition building, so the definitions refer to the names written to storage. It also camel-cases read model container names; both the default policy and the camel case policy pluralize those names by default.
Choose the policy before the client initializes. This is a client dependency, not an ASP.NET Core JSON setting.
Using a Direct Client
Section titled “Using a Direct Client”When constructing ChronicleClient yourself, pass CamelCaseNamingPolicy through the named namingPolicy argument:
using Cratis.Chronicle;using Cratis.Serialization;
public static class CamelCasingDirectClient{ public static ChronicleClient Create() => new(options: new ChronicleOptions(), namingPolicy: new CamelCaseNamingPolicy());}Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Using ASP.NET Core
Section titled “Using ASP.NET Core”For an ASP.NET Core host, set the policy during Chronicle registration so the client created by dependency injection uses it.
Basic Configuration
Section titled “Basic Configuration”In Program.cs, call WithCamelCaseNamingPolicy() in the configure callback. That callback receives the IChronicleBuilder for client dependencies:
using Microsoft.AspNetCore.Builder;
public static class CamelCasingAspNetCoreBasicRegistration{ public static void Configure(string[] args) { var builder = WebApplication.CreateBuilder(args);
builder.AddCratisChronicle( configure: chronicleBuilder => chronicleBuilder.WithCamelCaseNamingPolicy());
var app = builder.Build(); }}Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Dependency Injection Configuration
Section titled “Dependency Injection Configuration”Keep runtime settings in configureOptions and the naming policy in configure. Here, EventStore selects the store while the builder selects how its client names properties:
using Microsoft.AspNetCore.Builder;
public static class CamelCasingAspNetCoreWithOptionsRegistration{ public static void Configure(string[] args) { var builder = WebApplication.CreateBuilder(args);
builder.AddCratisChronicle( configureOptions: options => options.EventStore = "MyEventStore", configure: chronicleBuilder => chronicleBuilder.WithCamelCaseNamingPolicy());
var app = builder.Build(); }}Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Using .NET Host (Worker Services)
Section titled “Using .NET Host (Worker Services)”Worker services and other non-web hosts use the same configure callback on IHostApplicationBuilder:
using Microsoft.Extensions.Hosting;
public static class CamelCasingWorkerHostRegistration{ public static void Configure(string[] args) { var builder = Host.CreateApplicationBuilder(args);
builder.AddCratisChronicle( configure: chronicleBuilder => chronicleBuilder.WithCamelCaseNamingPolicy());
var host = builder.Build(); }}Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Impact on Projections
Section titled “Impact on Projections”The policy connects the C# properties in a projection to their serialized names. Your C# types keep their original property names.
Projection Definition Building
Section titled “Projection Definition Building”When the client builds a projection definition, it applies the policy to property mappings. A mapping for FirstName therefore refers to firstName in the stored data.
Read Models
Section titled “Read Models”The read model container name identifies where a sink stores the model. With CamelCaseNamingPolicy configured, the CamelCasingUserReadModel type below produces the container name camelCasingUserReadModels.
The following event and read model use C# property names. The projection then maps between their serialized forms.
Event Definition
Section titled “Event Definition”using Cratis.Chronicle.Events;
[EventType]public record CamelCasingUserRegistered( string FirstName, string LastName, string EmailAddress, DateTime RegistrationDate);import io.cratis.chronicle.events.EventTypeimport java.time.Instant
@EventTypedata class CamelCasingUserRegistered( val firstName: String = "", val lastName: String = "", val emailAddress: String = "", val registrationDate: Instant = Instant.EPOCH)import io.cratis.chronicle.events.EventType;
import java.time.Instant;
@EventTyperecord CamelCasingUserRegistered( String firstName, String lastName, String emailAddress, Instant registrationDate) {}defmodule MyApp.Events.CamelCasingUserRegistered do use Cratis.Chronicle.Events.EventType, id: "camel-casing-user-registered"
defstruct [:first_name, :last_name, :email_address, :registration_date]endTypeScript does not support this workflow yet.Read Model Definition
Section titled “Read Model Definition”public class CamelCasingUserReadModel{ public string FirstName { get; set; } = string.Empty; public string LastName { get; set; } = string.Empty; public string EmailAddress { get; set; } = string.Empty; public DateTime RegistrationDate { get; set; }}import io.cratis.chronicle.readModels.ReadModelimport java.time.Instant
@ReadModeldata class CamelCasingUserReadModel( val firstName: String = "", val lastName: String = "", val emailAddress: String = "", val registrationDate: Instant = Instant.EPOCH)import io.cratis.chronicle.readModels.ReadModel;
import java.time.Instant;
@ReadModelclass CamelCasingUserReadModel { public String firstName = ""; public String lastName = ""; public String emailAddress = ""; public Instant registrationDate = Instant.EPOCH;}defmodule MyApp.ReadModels.CamelCasingUser do use Cratis.Chronicle.ReadModels.ReadModel
defstruct first_name: nil, last_name: nil, email_address: nil, registration_date: nilendTypeScript does not support this workflow yet.Projection with Camel Case Naming Policy
Section titled “Projection with Camel Case Naming Policy”The projection’s .From<CamelCasingUserRegistered>() uses automatic property mapping. With the policy configured, those mappings use camelCase names:
using Cratis.Chronicle.Projections;
public class CamelCasingUserProjection : IProjectionFor<CamelCasingUserReadModel>{ public void Define(IProjectionBuilderFor<CamelCasingUserReadModel> builder) => builder .From<CamelCasingUserRegistered>();}import io.cratis.chronicle.projections.IProjectionForimport io.cratis.chronicle.projections.IProjectionBuilderFor
// Kotlin property names are already camelCase, so the projected read model properties below —// firstName, lastName, emailAddress, registrationDate — need no naming policy configuration to// come out as camelCase; that is simply how Kotlin properties are named.class CamelCasingUserProjection : IProjectionFor<CamelCasingUserReadModel> { override fun define(builder: IProjectionBuilderFor<CamelCasingUserReadModel>) { builder.from(CamelCasingUserRegistered::class) { it.set(CamelCasingUserReadModel::firstName).toProperty("firstName") it.set(CamelCasingUserReadModel::lastName).toProperty("lastName") it.set(CamelCasingUserReadModel::emailAddress).toProperty("emailAddress") it.set(CamelCasingUserReadModel::registrationDate).toProperty("registrationDate") } }}import io.cratis.chronicle.projections.IProjectionFor;import io.cratis.chronicle.projections.IProjectionBuilderFor;import io.cratis.chronicle.java.ProjectionBuilderJavaBridge;
// Java field names are already camelCase, and AutoMap matches read model properties to event// properties of the same name — firstName, lastName, emailAddress, registrationDate — so no// naming policy configuration is needed to have them come out as camelCase.class CamelCasingUserProjection implements IProjectionFor<CamelCasingUserReadModel> { @Override public void define(IProjectionBuilderFor<CamelCasingUserReadModel> builder) { ProjectionBuilderJavaBridge.from(builder, CamelCasingUserRegistered.class); }}defmodule MyApp.Projections.CamelCasingUserProjection do use Cratis.Chronicle.Projections.Projection, model: MyApp.ReadModels.CamelCasingUser
from MyApp.Events.CamelCasingUserRegistered, set: [ first_name: :first_name, last_name: :last_name, email_address: :email_address, registration_date: :registration_date ]endTypeScript does not support this workflow yet.The resulting read model properties are firstName, lastName, emailAddress, and registrationDate. These are the names to look for in the stored model.
Important Notes
Section titled “Important Notes”The policy applies to the projections built by that Chronicle client. It does not change general ASP.NET Core JSON serialization; configure that separately if your HTTP responses also need camelCase.
Changing the policy changes property paths and can change container names. Treat a change on an existing store as a storage-contract change, not just a display preference.
Troubleshooting
Section titled “Troubleshooting”Projection Property Names Not Converting
Section titled “Projection Property Names Not Converting”Check the client that builds the projection. It must receive the policy before initialization, either through WithCamelCaseNamingPolicy() on its builder or through the constructor’s namingPolicy argument. Configuring one client does not change another client instance.
Inconsistent Property Naming
Section titled “Inconsistent Property Naming”Compare the registered projection’s property paths with the stored model, including any custom mappings. After changing the policy, rebuild the projection definitions with the configured client. See Projections for the projection workflow, or Structural Dependencies to configure a custom naming policy.