CHR0001: Event type must have [EventType] attribute
Rule Description
Section titled “Rule Description”Types that are appended to event sequences must be marked with the [EventType] attribute. This ensures that all events in the event store are properly identified and can be correctly deserialized.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”// Missing [EventType] attributepublic record UserCreated(string Username, string Email);
public class UserService{ private readonly IEventSequence _eventSequence;
public async Task CreateUser(string username, string email) { // CHR0001: Type 'UserCreated' must be marked with [EventType] attribute await _eventSequence.Append( eventSourceId: userId, @event: new UserCreated(username, email)); }}using Cratis.Chronicle.Concepts.Events;
[EventType]public record UserCreated(string Username, string Email);
public class UserService{ private readonly IEventSequence _eventSequence;
public async Task CreateUser(string username, string email) { // Now valid await _eventSequence.Append( eventSourceId: userId, @event: new UserCreated(username, email)); }}Quick Fix
Section titled “Quick Fix”The analyzer provides a code fix that automatically:
- Adds the
[EventType]attribute to the event type - Adds the required using directive if not already present
Why This Rule Exists
Section titled “Why This Rule Exists”The [EventType] attribute is crucial for Chronicle’s event handling:
- It uniquely identifies the event type in the event store
- It enables proper event serialization and deserialization
- It allows Chronicle to track event type generations and schemas
- It ensures type safety when working with events