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”// Missing [EventType] attributepublic 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; }}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
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