CHR0007: Reducer event parameter must have [EventType] attribute
Rule Description
Section titled “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
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Reducers;
// Missing [EventType] attributepublic record Chr0007InventoryAdjusted(string ProductId, int Quantity);
public class Chr0007InventoryState{ public int Quantity { get; set; }}
public class Chr0007InventoryReducer : IReducerFor<Chr0007InventoryState>{ // CHR0007: Type 'Chr0007InventoryAdjusted' must be marked with [EventType] attribute public void Adjusted(Chr0007InventoryAdjusted @event) { }}using Cratis.Chronicle.Events;using Cratis.Chronicle.Reducers;
[EventType]public record Chr0007InventoryAdjustedFixed(string ProductId, int Quantity);
public class Chr0007InventoryStateFixed{ public int Quantity { get; set; }}
public class Chr0007InventoryReducerFixed : IReducerFor<Chr0007InventoryStateFixed>{ // Now valid public void Adjusted(Chr0007InventoryAdjustedFixed @event) { }}Quick Fix
Section titled “Quick Fix”The analyzer provides a code fix that automatically adds the [EventType] attribute to the event parameter type.
Why This Rule Exists
Section titled “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