scaffold-single-stream-projection

Create a Marten SingleStreamProjection class and register it with ProjectionLifecycle.Async.

15|Updated Dec 25, 2025
One-click install
npx skills add https://github.com/aalmada/BookStore --skill scaffold-single-stream-projection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: scaffold-single-stream-projection
Source: https://github.com/aalmada/BookStore/tree/main/.claude/skills/scaffold-single-stream-projection
Command: npx skills add https://github.com/aalmada/BookStore --skill scaffold-single-stream-projection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps build a Marten Single Stream Projection that materializes a single read model from one aggregate's event stream, enabling fast reads and simplified queries for a given aggregate.

Core Features & Use Cases

  • Define the Projection Class: Create a {Resource}Projection class in src/BookStore.ApiService/Projections/ that inherits from SingleStreamProjection<T>, using the provided template at templates/Projection.cs.
  • Register & Configure in Marten: Wire up the projection in Marten via the infrastructure configuration (e.g., options.Projections.Add<YourProjection>(ProjectionLifecycle.Async)) to optimize for performance.
  • Indexing (Optional): Add a schema index for common query fields to improve read performance.
  • Querying: Load the projection by stream ID or query on relevant fields to serve read-model data.
  • Use Case: Build per-aggregate read models (e.g., AuthorDetails) from a single event stream to power fast UI reads or API endpoints.

Quick Start

Use the scaffold-single-stream-projection to generate an AuthorDetailsProjection, register it in Marten, and then query by the streamId to load the projection.

Frequently Asked Questions about scaffold-single-stream-projection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Marten single stream projection for a read model?

To create a Marten single stream projection, define a class inheriting from SingleStreamProjection<T> in your Projections folder and register it with options.Projections.Add using ProjectionLifecycle.Async for fast per-aggregate reads.

What is a single stream projection used for in event sourcing?

A single stream projection is used in event sourcing to aggregate events from one stream into a read model, enabling fast reads and simplified queries for a specific aggregate.

How do I register a projection in Marten with ProjectionLifecycle.Async?

You register a projection in Marten by calling options.Projections.Add<YourProjection>(ProjectionLifecycle.Async) during infrastructure configuration to optimize read model performance asynchronously.

Can I index query fields in a Marten single stream projection?

Yes, you can optionally add a schema index for common query fields in your Marten single stream projection to improve read performance when querying the read model.

When should I use a single stream projection instead of a multi-stream projection in Marten?

Use a Marten single stream projection when you need per-aggregate views from one event stream, rather than aggregating events across multiple streams.

How do I query a Marten read model generated by a single stream projection?

You query a Marten read model by loading the single stream projection by its stream ID or querying on relevant indexed fields to serve read-model data for UI or API endpoints.