Table of Contents

CHR0006: Reducer method signature must match allowed signatures

Rule Description

Methods in reducer classes must follow one of the allowed signatures for event handling. This ensures proper integration with Chronicle's reducer infrastructure.

Severity

Warning

Allowed Signatures

Event handler methods in reducers must have one of the following signatures:

// Async with event only
Task MethodName(TEvent @event)

// Async with event and context
Task MethodName(TEvent @event, EventContext context)

// Synchronous with event only
void MethodName(TEvent @event)

// Synchronous with event and context
void MethodName(TEvent @event, EventContext context)

Where TEvent is a type marked with [EventType].

Example

Violation

public class ShoppingCartReducer : IReducerFor<ShoppingCart>
{
    // CHR0006: Invalid signature - returns Task<int> instead of Task
    public async Task<int> ItemAdded(ItemAdded @event)
    {
        // Update cart
        return 1;
    }

    // CHR0006: Invalid signature - too many parameters
    public async Task ItemRemoved(ItemRemoved @event, EventContext context, bool validate)
    {
        // Update cart
    }
}

Fix

public class ShoppingCartReducer : IReducerFor<ShoppingCart>
{
    // Valid signature
    public async Task ItemAdded(ItemAdded @event)
    {
        // Update cart
    }

    // Valid signature with context
    public async Task ItemRemoved(ItemRemoved @event, EventContext context)
    {
        // Update cart
    }

    // Valid synchronous signature
    public void CartCleared(CartCleared @event)
    {
        // Clear cart
    }
}

Why This Rule Exists

Reducers maintain state by processing events in sequence. Standardized method signatures ensure:

  • Predictable reducer behavior
  • Proper infrastructure integration
  • Clear code patterns across the codebase
  • Reliable state management
  • CHR0004: Reactor method signatures
  • CHR0007: Reducer event parameter must have [EventType] attribute