From All
FromAll is the .NET client name for a projection-wide every-event mapping. Other clients expose the same Chronicle definition through their every-event APIs, so use From Every Event for the portable, multi-client concept.
Use FromAll in .NET when you want a property mapping to apply across the event types considered by the projection, especially when defining the projection with the fluent API.
Fluent .NET Projection
Section titled “Fluent .NET Projection”The fluent .FromAll(...) API maps read model properties from event context for all events in the projection definition.
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));}Model-Bound Attribute
Section titled “Model-Bound Attribute”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.
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; }}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.
Choosing Between FromAll And FromEvery
Section titled “Choosing Between FromAll And FromEvery”| API | Use it when |
|---|---|
.FromAll(...) | You are using the .NET fluent projection API and want to define an all-events mapping in the projection class. |
[FromAll] | You are using .NET model-bound projections and convention-based payload mapping is enough. |
[FromEvery(...)] | You are using .NET model-bound projections and need to name an event payload or event context source explicitly. |
| Other clients’ every-event API | You are writing Kotlin, Elixir, TypeScript, or another client and the client exposes the concept under a different name. |
Limitations
Section titled “Limitations”FromAllis a .NET client API name, not the portable name used by every client.- 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.