Follow this guide to create a Multi-Stream Projection (View Projection) in Marten. This allows you to aggregate data across many different streams into a single document (or multiple documents based on grouping).
- •
Define the Projection Class
- •Create a
classinsrc/BookStore.ApiService/Projections/ - •Naming:
{Summary}Projection(e.g.,AuthorDashboardProjectionorMonthlySalesProjection) - •Base Class:
MultiStreamProjection<T, TId> - •Template:
templates/Projection.cs
- •Create a
- •
Configure in Marten
- •Open
src/BookStore.ApiService/Infrastructure/Extensions/MartenConfigurationExtensions.cs - •Register:
csharp
options.Projections.Add<AuthorDashboardProjection>(ProjectionLifecycle.Async);
- •Open
- •
Indexing
- •Add indexes in
ConfigureIndexesif you need to query by fields other than Id.
- •Add indexes in
Related Skills
- •
/scaffold-single-stream-projection: If you only need data from one stream. - •
/scaffold-event-projection: If you need 1:1 transformation without aggregation.