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”// Missing [EventType] attributepublic record CustomerRegistered(Guid CustomerId, string Email);
public class CustomerReactor : IReactor{ // CHR0005: Type 'CustomerRegistered' must be marked with [EventType] attribute public async Task Registered(CustomerRegistered @event) { // Send welcome email await SendWelcomeEmail(@event.Email); }}using Cratis.Chronicle.Concepts.Events;
[EventType]public record CustomerRegistered(Guid CustomerId, string Email);
public class CustomerReactor : IReactor{ // Now valid public async Task Registered(CustomerRegistered @event) { // Send welcome email await SendWelcomeEmail(@event.Email); }}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