Projection with FromAll
The FromAll() method configures a projection to receive and process every event in the event log, regardless of event type. This complements the type-specific From<TEvent>() calls and is useful for tracking metadata properties that should be updated whenever any event occurs.
Basic Usage
Section titled “Basic Usage”public class UserProfileProjection : IProjectionFor<UserProfile>{ public void Define(IProjectionBuilderFor<UserProfile> builder) => builder .AutoMap() .FromAll(_ => _ .Set(m => m.LastUpdated).ToEventContextProperty(c => c.Occurred)) .From<UserCreated>() .From<UserEmailChanged>() .From<UserNameChanged>();}LastUpdated is updated for every event type — not just the three listed in From<>.
Available Mappings
Section titled “Available Mappings”Event Context Properties
Section titled “Event Context Properties”Map to any property on the event context:
.FromAll(_ => _ .Set(m => m.LastUpdated).ToEventContextProperty(c => c.Occurred) .Set(m => m.LastEventSequence).ToEventContextProperty(c => c.SequenceNumber) .Set(m => m.LastCorrelationId).ToEventContextProperty(c => c.CorrelationId))Event Source ID
Section titled “Event Source ID”.FromAll(_ => _ .Set(m => m.EventSourceId).ToEventSourceId())Examples
Section titled “Examples”User Profile with Audit
Section titled “User Profile with Audit”public record UserProfile( string UserId, string Name, string Email, DateTimeOffset LastUpdated, ulong LastEventSequence);
public class UserProfileProjection : IProjectionFor<UserProfile>{ public void Define(IProjectionBuilderFor<UserProfile> builder) => builder .AutoMap() .FromAll(_ => _ .Set(m => m.LastUpdated).ToEventContextProperty(c => c.Occurred) .Set(m => m.LastEventSequence).ToEventContextProperty(c => c.SequenceNumber)) .From<UserCreated>() .From<UserEmailChanged>() .From<UserNameChanged>();}Order with Full Tracking
Section titled “Order with Full Tracking”public record Order( string OrderId, string OrderNumber, string CustomerId, string Status, DateTimeOffset LastModified, IEnumerable<OrderItem> Items);
public class OrderProjection : IProjectionFor<Order>{ public void Define(IProjectionBuilderFor<Order> builder) => builder .AutoMap() .FromAll(_ => _ .Set(m => m.LastModified).ToEventContextProperty(c => c.Occurred)) .From<OrderCreated>(_ => _ .Set(m => m.Status).To(_ => "Placed")) .From<OrderShipped>(_ => _ .Set(m => m.Status).To(_ => "Shipped")) .Children(m => m.Items, children => children .IdentifiedBy(e => e.ProductId) .AutoMap() .From<ItemAddedToOrder>(_ => _ .UsingKey(e => e.ProductId)));}Difference Between FromAll() and FromEvery()
Section titled “Difference Between FromAll() and FromEvery()”Both FromAll() and FromEvery() apply mappings to all events. Use FromAll() to express that the projection subscribes to all event types; use FromEvery() when you only need common per-event side effects and have explicit From<TEvent>() calls elsewhere.
| Feature | FromAll() | FromEvery() |
|---|---|---|
| Applies to | All event types | All event types |
| Typical use | Subscribe to all events | Audit / common metadata |
| Include children | Yes (default) | Configurable |
Common Use Cases
Section titled “Common Use Cases”Audit Timestamps
Section titled “Audit Timestamps”.FromAll(_ => _ .Set(m => m.LastModified).ToEventContextProperty(c => c.Occurred))Event Sequencing
Section titled “Event Sequencing”.FromAll(_ => _ .Set(m => m.LastEventSequence).ToEventContextProperty(c => c.SequenceNumber))Correlation Tracking
Section titled “Correlation Tracking”.FromAll(_ => _ .Set(m => m.LastOperationId).ToEventContextProperty(c => c.CorrelationId))Best Practices
Section titled “Best Practices”- Use for metadata:
FromAll()is best suited for audit-style properties (timestamps, sequence numbers, correlation IDs). - Avoid business logic: Do not use
FromAll()for properties that should only change under specific event conditions. - Prefer context properties: Mapping from event context properties is more robust than mapping from event data properties, because all events share the same context shape.