Skip to content

CHR0006: Reducer method signature must match allowed signatures

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

Warning

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

using Cratis.Chronicle.Events;
public interface Chr0006ValidReducerMethodSignatures<TEvent>
{
// Async with event only
Task MethodNameAsync(TEvent @event);
// Async with event and context
Task MethodNameAsync(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].

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reducers;
public record Chr0006ItemAdded(string ProductId);
public record Chr0006ItemRemoved(string ProductId);
public class Chr0006ShoppingCart
{
public int ItemCount { get; set; }
}
public class Chr0006InvalidShoppingCartReducer : IReducerFor<Chr0006ShoppingCart>
{
// CHR0006: Invalid signature - returns Task<int> instead of Task
public async Task<int> ItemAdded(Chr0006ItemAdded @event)
{
await Task.CompletedTask;
return 1;
}
// CHR0006: Invalid signature - too many parameters
public Task ItemRemoved(Chr0006ItemRemoved @event, EventContext context, bool validate) =>
Task.CompletedTask;
}
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reducers;
public record Chr0006ItemAddedFixed(string ProductId);
public record Chr0006ItemRemovedFixed(string ProductId);
public record Chr0006CartCleared;
public class Chr0006ShoppingCartFixed
{
public int ItemCount { get; set; }
}
public class Chr0006ValidShoppingCartReducer : IReducerFor<Chr0006ShoppingCartFixed>
{
// Valid signature
public Task ItemAdded(Chr0006ItemAddedFixed @event) => Task.CompletedTask;
// Valid signature with context
public Task ItemRemoved(Chr0006ItemRemovedFixed @event, EventContext context) => Task.CompletedTask;
// Valid synchronous signature
public void CartCleared(Chr0006CartCleared @event)
{
}
}

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