Skip to content

Cratis Chronicle projection tags

Projection tags in Cratis Chronicle label a projection definition with its purpose or domain, such as Analytics or Inventory. Use them to describe what a projection is for. They do not filter the events it observes or select projections for operations such as rebuilds.

To control projection input, declare the event types and select the event sequence. If you need a reducer or reactor to process only events with particular metadata, use appended event metadata filters instead of projection tags.

Choose the form that keeps the labels readable beside the projection. A single tag, several tags in one attribute or decorator, and repeated attributes or decorators all label the same definition.

Place a tag on the projection class. In this example, Analytics describes the projection’s purpose:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record TaggingOrderPlaced(string OrderId);
[EventType]
public record TaggingItemAddedToOrder(decimal Amount);
public record TaggingOrderAnalytics(string OrderId, decimal TotalAmount);
[Tag("Analytics")]
public class TaggingOrderAnalyticsProjection : IProjectionFor<TaggingOrderAnalytics>
{
public void Define(IProjectionBuilderFor<TaggingOrderAnalytics> builder) => builder
.From<TaggingOrderPlaced>()
.From<TaggingItemAddedToOrder>(_ => _
.Add(m => m.TotalAmount).With(e => e.Amount));
}

View C# snippet source on GitHub

Pass several names to label a projection for more than one purpose. The C# attribute uses params; the TypeScript decorator accepts multiple names too:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record TaggingSaleRecorded(string ProductId, decimal Amount);
public record TaggingSalesReport(string ProductId, decimal TotalSales);
[Tag("Analytics", "Reporting", "Dashboard")]
public class TaggingSalesReportProjection : IProjectionFor<TaggingSalesReport>
{
public void Define(IProjectionBuilderFor<TaggingSalesReport> builder) => builder
.From<TaggingSaleRecorded>(_ => _
.Add(m => m.TotalSales).With(e => e.Amount));
}

View C# snippet source on GitHub

You can put each tag on its own line with repeated [Tag] attributes or @tag decorators:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record TaggingAuditEntryRecorded(string EntryId, string Category);
public record TaggingComplianceReport(string EntryId, string Category);
[Tag("Analytics")]
[Tag("Compliance")]
[Tag("Auditing")]
public class TaggingComplianceReportProjection : IProjectionFor<TaggingComplianceReport>
{
public void Define(IProjectionBuilderFor<TaggingComplianceReport> builder) => builder
.From<TaggingAuditEntryRecorded>();
}

View C# snippet source on GitHub

You can also combine multi-name and repeated annotations on the same class:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Projections;
[EventType]
public record TaggingKpiRecorded(string Kpi, decimal Value);
public record TaggingExecutiveDashboard(string Kpi, decimal Value);
[Tag("Analytics", "Reporting")]
[Tag("Executive")]
public class TaggingExecutiveDashboardProjection : IProjectionFor<TaggingExecutiveDashboard>
{
public void Define(IProjectionBuilderFor<TaggingExecutiveDashboard> builder) => builder
.From<TaggingKpiRecorded>();
}

View C# snippet source on GitHub

A model-bound projection declares its mappings on the read model itself, so put the tags on that type. The Inventory and Operations labels below become metadata on its projection definition; they do not change the event mapping:

using Cratis.Chronicle;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Keys;
using Cratis.Chronicle.Projections.ModelBound;
[EventType]
public record TaggingProductRegistered(Guid ProductId, string Name, int QuantityInStock, decimal UnitPrice);
[Tag("Inventory", "Operations")]
[FromEvent<TaggingProductRegistered>(key: nameof(TaggingProductRegistered.ProductId))]
public record TaggingProductInventory(
[Key] Guid ProductId,
string Name,
int QuantityInStock,
decimal UnitPrice);

View C# snippet source on GitHub

Choose names a teammate can recognize without opening the projection’s mappings. Reuse the same spelling for the same domain or purpose across projections, and add a tag only when it helps describe the projection. This gives related definitions a shared vocabulary without implying that Chronicle groups them for execution.

The following examples label projections by purpose, business domain, and stakeholder. Pick the categories that help someone understand your application’s read models:

using Cratis.Chronicle;
using Cratis.Chronicle.Projections;
public record TaggingCategoryExamples(Guid Id);
// By domain
[Tag("Sales", "Inventory", "Customer")]
// By purpose
[Tag("Analytics", "Reporting", "Dashboard", "Search")]
// By stakeholder
[Tag("Executive", "Operations", "Finance")]
// By consistency model
[Tag("Immediate", "Eventual")]
// By data type
[Tag("Aggregates", "Lists", "Details")]
public class TaggingCategoryExamplesProjection : IProjectionFor<TaggingCategoryExamples>
{
public void Define(IProjectionBuilderFor<TaggingCategoryExamples> builder)
{
}
}

View C# snippet source on GitHub

Projection tags are stored metadata, not a query or rebuild selector. Adding Analytics to several projections does not make Chronicle select or rebuild them as a group. To change which events build a read model, edit the projection’s event declarations or event sequence selection.

For the distinction between event tags and observer labels, read Tagging. If you are labeling other observers, continue with Reactors Tagging or Reducers Tagging.