Table of Contents

CHR0007: Reducer event parameter must have [EventType] attribute

Rule Description

Event parameters in reducer methods must be types marked with the [EventType] attribute. This ensures that reducers only handle properly identified event types.

Severity

Error

Example

Violation

// Missing [EventType] attribute
public record InventoryAdjusted(string ProductId, int Quantity);

public class InventoryReducer : IReducerFor<InventoryState>
{
    // CHR0007: Type 'InventoryAdjusted' must be marked with [EventType] attribute
    public void Adjusted(InventoryAdjusted @event)
    {
        // Update inventory
        State.Quantity += @event.Quantity;
    }
}

Fix

using Cratis.Chronicle.Concepts.Events;

[EventType]
public record InventoryAdjusted(string ProductId, int Quantity);

public class InventoryReducer : IReducerFor<InventoryState>
{
    // Now valid
    public void Adjusted(InventoryAdjusted @event)
    {
        // Update inventory
        State.Quantity += @event.Quantity;
    }
}

Quick Fix

The analyzer provides a code fix that automatically adds the [EventType] attribute to the event parameter type.

Why This Rule Exists

Reducers build state from events in a deterministic way. Ensuring all event types are properly marked:

  • Guarantees proper event routing to reducers
  • Enables type-safe state reduction
  • Ensures events are correctly serialized/deserialized
  • Maintains schema tracking for events
  • Allows for proper reducer replay and catchup
  • CHR0001: Event sequence append operations
  • CHR0005: Reactor event parameters
  • CHR0006: Reducer method signatures