Follow this guide to create a Composite Projection in Marten (v8.18+).
- •
Define the Projection Class
- •Create a
classinsrc/BookStore.ApiService/Projections/ - •Naming:
{Summary}Projection(typically a View Projection) - •Base Class:
MultiStreamProjection<T, TId>(usually) or custom. - •Template:
templates/Projection.cs
- •Create a
- •
Configure in Marten
- •Open
src/BookStore.ApiService/Infrastructure/Extensions/MartenConfigurationExtensions.cs - •Register using
CompositeProjectionFor:csharpoptions.Projections.CompositeProjectionFor("GroupDetails", projection => { // Stage 1: Basic Projections projection.Add<UserProjection>(); projection.Add<OrderProjection>(); // Stage 2: Dependent Projections (inputs from Stage 1) projection.Add<UserDashboardProjection>(2); });
- •Open
- •
Indexing
- •Configure indexes as usual in
ConfigureIndexes.
- •Configure indexes as usual in
Related Skills
- •
/scaffold-multi-stream-projection: For standard multi-stream aggregates. - •
/scaffold-single-stream-projection: For standard single-stream aggregates.