Skip to content

Camel Casing

Chronicle can apply a camel case naming policy when building projection definitions and persisting read models. This keeps property names consistent with common JSON naming conventions.

By default, Chronicle uses property names as they appear in C# (PascalCase). Enabling camel case will:

  • Govern how projection definitions are built
  • Determine the property names used when projections update read models
  • Keep naming consistent across projection and read model data

For direct ChronicleClient usage outside of a hosted application, pass a CamelCaseNamingPolicy instance via the named namingPolicy constructor argument:

using Cratis.Chronicle;
using Cratis.Serialization;
public static class CamelCasingDirectClient
{
public static ChronicleClient Create() =>
new(options: new ChronicleOptions(), namingPolicy: new CamelCaseNamingPolicy());
}

When building ASP.NET Core applications, use the dependency injection extensions to configure Chronicle with camel case naming policy.

In your Program.cs file, configure Chronicle with camel case naming policy using the IChronicleBuilder callback:

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();
}
}

You can combine camel case naming policy with other Chronicle configuration options:

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();
}
}

For worker services or other non-web hosts using 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();
}
}

The naming policy configuration affects how Chronicle handles projections:

When you configure camel case naming policy, Chronicle uses this policy when building projection definitions. This means property mappings within projections will use camel case property names.

The naming policy affects the read model container name, which affects the name of the collection, table, or file that data is persisted as.

When projections project to read models, the property names used will follow the configured naming policy. For example:

using Cratis.Chronicle.Events;
[EventType]
public record CamelCasingUserRegistered(
string FirstName,
string LastName,
string EmailAddress,
DateTime RegistrationDate);
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; }
}

With camel case naming policy configured, Chronicle will use camel case property names when building the projection:

using Cratis.Chronicle.Projections;
public class CamelCasingUserProjection : IProjectionFor<CamelCasingUserReadModel>
{
public void Define(IProjectionBuilderFor<CamelCasingUserReadModel> builder) => builder
.From<CamelCasingUserRegistered>(_ => _
.Set(m => m.FirstName).To(e => e.FirstName)
.Set(m => m.LastName).To(e => e.LastName)
.Set(m => m.EmailAddress).To(e => e.EmailAddress)
.Set(m => m.RegistrationDate).To(e => e.RegistrationDate));
}

The resulting read model data will have camel case property names: firstName, lastName, emailAddress, registrationDate.

  • The naming policy affects how Chronicle builds projection definitions internally.
  • Property names in read models will follow the configured naming policy when data is persisted.
  • This configuration is specific to Chronicle operations and does not affect general ASP.NET Core JSON serialization.
  • All projections in your application will use the same naming policy once configured.

If projection property names are not being converted to camel case:

  1. Verify that WithCamelCaseNamingPolicy() is called on the IChronicleBuilder during Chronicle configuration.
  2. Ensure the configuration is applied before Chronicle services are initialized.
  3. Check that all projections are using the same Chronicle client instance.

If you see inconsistent property naming in your read models:

  1. Verify that Chronicle is configured with the camel case naming policy via IChronicleBuilder.WithCamelCaseNamingPolicy().
  2. Check if any custom property mappings are overriding the global naming policy.
  3. Ensure all projection definitions are rebuilt after changing the naming policy.