CHR0016: Projection Define() must not contain imperative code
Rule Description
Section titled “Rule Description”The Define() method of a class implementing IProjectionFor<T> must not contain imperative statements such as if/else, loops, variable declarations, or assignments. Projection definitions only declare the shape; they do not execute.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Projections;
public class UserReadModel { }
public class UserProjection : IProjectionFor<UserReadModel>{ public void Define(IProjectionBuilderFor<UserReadModel> builder) { if (someCondition) { builder.From<UserRegistered>(_ => _); } }}using Cratis.Chronicle.Projections;
public class UserReadModel { }
public class UserProjection : IProjectionFor<UserReadModel>{ public void Define(IProjectionBuilderFor<UserReadModel> builder) => builder.From<UserRegistered>(_ => _);}Why This Rule Exists
Section titled “Why This Rule Exists”The Define() method is called once at registration time to declare the projection shape. Chronicle serializes the resulting definition and sends it to the server for use during both live processing and replay. Any imperative code such as conditionals or loops creates non-determinism: different runs could produce different projection definitions, breaking replay consistency.