CHR0003: Model bound projection attribute must reference event type with [EventType] attribute
Rule Description
Section titled “Rule Description”Model bound projection attributes (such as FromEventAttribute<TEvent>, RemovedWithAttribute<TEvent>, etc.) must reference types that are marked with the [EventType] attribute.
Severity
Section titled “Severity”Error
Example
Section titled “Example”Violation
Section titled “Violation”using Cratis.Chronicle.Projections.ModelBound;
// Missing [EventType] attributepublic record Chr0003ProductAdded(Guid ProductId, string Name, decimal Price);
// CHR0003: Type 'Chr0003ProductAdded' must be marked with [EventType] attribute[FromEvent<Chr0003ProductAdded>]public class Chr0003ProductReadModel{ public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public decimal Price { get; set; }}using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record Chr0003ProductAddedFixed(Guid ProductId, string Name, decimal Price);
// Now valid[FromEvent<Chr0003ProductAddedFixed>]public class Chr0003ProductReadModelFixed{ public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public decimal Price { get; set; }}Applicable Attributes
Section titled “Applicable Attributes”This rule applies to the following model bound projection attributes:
FromEventAttribute<TEvent>RemovedWithAttribute<TEvent>RemovedWithJoinAttribute<TEvent>JoinAttribute<TEvent>ChildrenFromAttribute<TEvent>FromEveryAttribute<TEvent>
Quick Fix
Section titled “Quick Fix”The analyzer provides a code fix that automatically adds the [EventType] attribute to the referenced event type.
Why This Rule Exists
Section titled “Why This Rule Exists”Model bound projections use attributes to define how events map to read models. These attributes must reference valid event types to ensure:
- Proper event-to-model mapping
- Correct projection materialization
- Type-safe projection definitions
- Accurate event handling