Table of Contents

Tagging Reducers

Tags provide a way to organize and categorize your reducers for better discoverability and management. By applying the [Tag] attribute to your reducer classes, you can assign one or more tags that describe the purpose or domain of the reducer.

[Tag] and [Tags] label the reducer itself. They do not filter which appended events the reducer handles. For event filtering based on appended metadata, see Filter reducers and reactors by tag, Filter reducers and reactors by event source type, and Filter reducers and reactors by event stream type.

Adding Tags

You can tag reducers in multiple ways:

Single Tag

Apply a single tag to your reducer:

using Cratis.Chronicle;
using Cratis.Chronicle.Reducers;

[Tag("Analytics")]
public class OrderAnalyticsReducer : IReducerFor<OrderAnalytics>
{
    public OrderAnalytics OnOrderPlaced(OrderPlaced @event, OrderAnalytics? current, EventContext context)
    {
        // Reducer logic
    }
}

Multiple Tags (Single Attribute)

Use the params feature to specify multiple tags in a single attribute:

[Tag("Analytics", "Reporting", "Dashboard")]
public class SalesReportReducer : IReducerFor<SalesReport>
{
    // Reducer implementation
}

Multiple Tags (Multiple Attributes)

Apply multiple [Tag] attributes:

[Tag("Analytics")]
[Tag("Compliance")]
[Tag("Auditing")]
public class ComplianceReportReducer : IReducerFor<ComplianceReport>
{
    // Reducer implementation
}

Mixed Approach

Combine both approaches:

[Tag("Analytics", "Reporting")]
[Tag("Executive")]
public class ExecutiveDashboardReducer : IReducerFor<ExecutiveDashboard>
{
    // Reducer implementation
}

Best Practices

  • Use meaningful names: Choose tag names that clearly describe the purpose or domain
  • Be consistent: Establish tag naming conventions across your organization
  • Don't over-tag: Apply only relevant tags; too many can reduce their usefulness
  • Group related reducers: Use tags to group reducers that serve similar purposes

Common Tag Examples

Here are some common patterns for tagging reducers:

// By domain
[Tag("Sales")]
[Tag("Inventory")]
[Tag("Customer")]

// By purpose
[Tag("Analytics")]
[Tag("Reporting")]
[Tag("Dashboard")]
[Tag("Auditing")]

// By stakeholder
[Tag("Executive")]
[Tag("Operations")]
[Tag("Finance")]

// By data type
[Tag("Aggregates")]
[Tag("Summaries")]
[Tag("Metrics")]

Querying by Tag

Tags stored in the event store definition can be used for:

  • Filtering and searching for specific reducers
  • Organizing reducers in administrative interfaces
  • Generating documentation
  • Managing reducer deployments by tag

Note: The specific querying capabilities depend on your Chronicle setup and tooling.

See Also