---
title: 'CHR0016: Projection Define() must not contain imperative code'
---

## 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

Error

## Example

### Violation

```csharp
using Cratis.Chronicle.Projections;

public class UserReadModel { }

public class UserProjection : IProjectionFor<UserReadModel>
{
    public void Define(IProjectionBuilderFor<UserReadModel> builder)
    {
        if (someCondition)
        {
            builder.From<UserRegistered>(_ => _);
        }
    }
}
```

### Fix

```csharp
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

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.

## Related Rules

- [CHR0015](/chronicle/code-analysis/chr0015/): Projection must not have side effects
- [CHR0018](/chronicle/code-analysis/chr0018/): Constraint Define() must not contain imperative code
