AgentSkillsCN

scaffold-composite-projection

创建 Marten 复合投影,将多个投影串联起来,或按性能需求对投影进行分组。当需要将一个投影的输出作为另一个投影的输入,或为了优化守护进程的吞吐量时,可使用此技能。

SKILL.md
--- frontmatter
name: scaffold-composite-projection
description: Create a Marten Composite Projection to chain multiple projections or group them for performance. Use this when you need to use the output of one projection as the input for another, or to optimize daemon throughput.

Follow this guide to create a Composite Projection in Marten (v8.18+).

  1. Define the Projection Class

    • Create a class in src/BookStore.ApiService/Projections/
    • Naming: {Summary}Projection (typically a View Projection)
    • Base Class: MultiStreamProjection<T, TId> (usually) or custom.
    • Template: templates/Projection.cs
  2. Configure in Marten

    • Open src/BookStore.ApiService/Infrastructure/Extensions/MartenConfigurationExtensions.cs
    • Register using CompositeProjectionFor:
      csharp
      options.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);
      });
      
  3. Indexing

    • Configure indexes as usual in ConfigureIndexes.

Related Skills

  • /scaffold-multi-stream-projection: For standard multi-stream aggregates.
  • /scaffold-single-stream-projection: For standard single-stream aggregates.