Skip to content

From All

FromAll subscribes to every event type in the event sequence, including types not declared by the projection. It can create or update read-model instances for any event source, keyed by the event source id unless another key is configured. The declaration language’s all block has the same scope. If you only want the projection’s own handled event types, use From Every Event instead.

The fluent .FromAll(...) API maps read model properties for every event in the sequence. Use event context values for mappings that need to work across unrelated event payloads.

Fluent FromAll mapping
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections;
[EventType]
public record InventoryRegisteredFromAll(string ProductName);
[EventType]
public record InventoryAdjustedFromAll(int Quantity);
public record InventoryStatusFromAll(
[property: Key] Guid Id,
string ProductName,
DateTimeOffset LastUpdated);
public class InventoryStatusFromAllProjection : IProjectionFor<InventoryStatusFromAll>
{
public void Define(IProjectionBuilderFor<InventoryStatusFromAll> builder) => builder
.From<InventoryRegisteredFromAll>()
.From<InventoryAdjustedFromAll>()
.FromAll(_ => _
.Set(m => m.LastUpdated)
.ToEventContextProperty(c => c.Occurred));
}

View C# snippet source on GitHub

Combining fluent FromAll and FromEvery applies both sets of mappings to the projection’s handled event types; FromAll also covers otherwise-unhandled event types.

The [FromAll] attribute is also available in the .NET model-bound API. Use the no-argument form when the read model property name matches the event payload property name by convention.

Convention-based FromAll attribute
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections.ModelBound;
[EventType]
public record ProductRenamedFromAllConvention(string Name, int Version);
[EventType]
public record ProductPriceChangedFromAllConvention(decimal Price, int Version);
[FromEvent<ProductRenamedFromAllConvention>]
[FromEvent<ProductPriceChangedFromAllConvention>]
public record ProductVersionFromAllConvention
{
[Key]
public Guid Id { get; init; }
public string Name { get; init; } = string.Empty;
public decimal Price { get; init; }
[FromAll]
public int Version { get; init; }
}

View C# snippet source on GitHub

For explicit model-bound event payload or event context mappings, prefer [FromEvery(...)]. It creates the same every-event projection definition while making the source kind explicit. See From Every Event for examples.

In the .NET model-bound API, [FromAll] on a child or nested object’s property maps into that object, including on the event that creates it. For example, a child LastValue mapped from the event’s Value receives that value on its ChildrenFrom event. It does not write a root LastValue, even if the root declares a property with the same name.

A root mapping such as Source from the event source id stays on the root; it is not copied into children. Child-level attributes do not enable sequence-wide subscription on the root. Use a root [FromAll] when the root must subscribe to all events.

Older .NET clients, and the TypeScript client until it emits child-level mappings, send child mappings as bare root property names. The kernel moves such a mapping to each matching descendant only when the root schema does not declare that property. If both root and child declare it, the mapping stays at the root until you upgrade the client. Replay affected projections to rebuild previously materialized child values.

APIUse it when
.FromAll(...)You want a fluent mapping that subscribes to every event type in the sequence.
[FromAll]You want sequence-wide subscription with convention-based payload mapping in a .NET model-bound projection.
[FromEvery(...)]You want to map only handled event types, with an explicit event payload or event context source.
Other clients’ every-event APIYou are writing Kotlin, Elixir, TypeScript, or another client and the client exposes the concept under a different name.
  • A join-only event type is excluded from the separate all-events subscription to avoid double counting. Its FromAll mapping follows the join, so an event with no matching read-model instance does not create a fallback instance under its own event source id. To construct an instance for that type, declare it in From as well; it then receives the every-event mapping once through From.
  • FromAll is a .NET API name; the declaration language calls its sequence-wide subscription all.
  • The model-bound [FromAll] attribute is best kept to the convention-based form.
  • Use an event-specific mapping when a property should update only for selected event types.
  • Counting or incrementing into a dictionary-typed property with a dynamic, per-event key is available only through the fluent .FromAll(...) API today, not through [FromAll]. See Projection With FromAll.