Skip to content

FromAll: subscribe a Chronicle projection to every event type

FromAll subscribes a Chronicle projection to every event type in its event sequence, including types the projection does not declare. Use it when a read model needs to record activity across event sources. It can create or update instances keyed by the event source id unless another key is configured; join-only events have the exception described below.

The declaration language’s all block has the same scope. If you only need updates from event types the projection already handles, use From Every Event instead.

The fluent .FromAll(...) API maps read model properties for every event in the sequence. Event context, the metadata carried alongside an event, provides values such as occurrence time even when the payloads have no fields in common:

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

[FromAll] also accepts an explicit payload property or contextProperty. Keep [FromAll] when you need sequence-wide subscription: replacing it with [FromEvery(...)] narrows the subscription to handled event types. See From Every Event for the distinction between payload and context sources.

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 clients can send child mappings as bare root property names. The kernel moves such a mapping to each matching descendant only when child inclusion is enabled and the root schema does not declare that property. If both root and child declare it, the mapping stays at the root until the client sends a child-level mapping. Replay affected projections after upgrading the client to rebuild previously materialized child values.

API Use it when
.FromAll(...) You want a fluent mapping that subscribes to every event type in the sequence.
[FromAll] You want sequence-wide subscription in a .NET model-bound projection, using a payload or context value.
[FromEvery(...)] You want to map only handled event types, with an explicit event payload or event context source.
TypeScript fluent fromAll(...) You want the fluent mapping in the TypeScript client. It has the same sequence-wide subscription as .NET .FromAll(...).
TypeScript @fromAllEvents You want a model-bound TypeScript projection to subscribe to every event type. Only a root declaration widens the subscription; a child declaration maps into that child.
TypeScript @fromEvery You want to map only the projection’s handled event types in a TypeScript model-bound projection.

The TypeScript @fromAll decorator is a deprecated alias of @fromEvery: it maps only handled event types and does not subscribe to every event. Use @fromAllEvents for a sequence-wide subscription.

Fluent fromAll(...) requires Chronicle TypeScript client 6.42.0 or later. @fromAllEvents requires 6.44.0 or later.

  • 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.
  • The sequence-wide subscription is spelled FromAll in .NET, fromAll(...) (fluent) and @fromAllEvents (model-bound) in TypeScript, and all in the declaration language.
  • 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.