CHR0005: Reactor event parameter must have [EventType] attribute
Rule Description
Section titled “Rule Description”Event parameters in reactor methods must be types marked with the [EventType] attribute. This ensures that reactors only handle properly identified event types.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Reactors;
// Missing [EventType] attributepublic record Chr0005CustomerRegistered(Guid CustomerId, string Email);
public class Chr0005CustomerReactor : IReactor{ // CHR0005: Type 'Chr0005CustomerRegistered' must be marked with [EventType] attribute public Task Registered(Chr0005CustomerRegistered @event) => Task.CompletedTask;}using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record Chr0005CustomerRegisteredFixed(Guid CustomerId, string Email);
public class Chr0005CustomerReactorFixed : IReactor{ // Now valid public Task Registered(Chr0005CustomerRegisteredFixed @event) => Task.CompletedTask;}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”Reactors handle side effects when events occur. Ensuring all event types are properly marked:
- Guarantees proper event routing to reactors
- Enables type-safe event handling
- Ensures events are correctly serialized/deserialized
- Maintains schema tracking for events