Skip to content

Event Sequence Source

By default, model-bound projections read from the event log. Use [EventSequence] to specify a different event sequence:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections.ModelBound;
[EventType]
public record MbEventSeqOrderPlaced(decimal Amount);
[EventSequence("custom-sequence")]
public record MbEventSeqOrderSummary(
[Key]
Guid Id,
[SetFrom<MbEventSeqOrderPlaced>(nameof(MbEventSeqOrderPlaced.Amount))]
decimal TotalAmount);

This corresponds to the fluent API for declarative projections:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Projections;
[EventType]
public record MbEventSeqFluentOrderPlaced(decimal Amount);
public class MbEventSeqFluentOrderProjection : IProjectionFor<MbEventSeqFluentOrderSummary>
{
public void Define(IProjectionBuilderFor<MbEventSeqFluentOrderSummary> builder) => builder
.FromEventSequence(new EventSequenceId("custom-sequence"))
.From<MbEventSeqFluentOrderPlaced>(_ => _
.Set(m => m.TotalAmount).To(e => e.Amount));
}
public class MbEventSeqFluentOrderSummary
{
public decimal TotalAmount { get; set; }
}

Use [EventLog] when you want to be explicit that the projection reads from the default event log, even when other event types in the assembly carry a [EventStore] attribute:

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Keys;
[EventType]
public record MbEventSeqLocalEvent(string Data);
[EventLog]
public record MbEventSeqLocalSnapshot(
[Key]
Guid Id,
[SetFrom<MbEventSeqLocalEvent>(nameof(MbEventSeqLocalEvent.Data))]
string Data);

When the event types used in a model-bound projection carry a [EventStore] attribute pointing to a different event store than the one the projection is registered in, Chronicle automatically routes the projection to the corresponding inbox sequence — no [EventSequence] annotation needed.

When the [EventStore] attribute points to the same event store as the current one, Chronicle routes to the event log instead.

  • When you need to read from a specific sequence other than the inferred one
  • To suppress automatic inbox routing for a projection that handles foreign events
  • For projections that target a specialized or partitioned event stream

Note: The old [FromEventSequence] attribute has been removed. Use [EventSequence] instead.