CHR0006: Reducer method signature must match allowed signatures
Rule Description
Section titled “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
Section titled “Severity”Warning
Allowed Signatures
Section titled “Allowed Signatures”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].
Example
Section titled “Example”Violation
Section titled “Violation”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) { }}Why This Rule Exists
Section titled “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