Skip to content

docs: LoadAsync / strong-typed id codegen sample (GH-2508)#2544

Merged
jeremydmiller merged 1 commit intomainfrom
feature/2508-loadasync-strongtyped-ids-sample
Apr 20, 2026
Merged

docs: LoadAsync / strong-typed id codegen sample (GH-2508)#2544
jeremydmiller merged 1 commit intomainfrom
feature/2508-loadasync-strongtyped-ids-sample

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Documentation-only. Adds a "Custom Variable Sources" section to docs/guide/codegen.md adapted from the CritterStackSamples/Reports sample and Jeremy's April 20, 2026 blog post.

Covers the pattern of using an IVariableSource to materialize strong-typed identifiers (or any custom type) as a handler parameter — pulling the async factory call out of the handler body and into the generated wrapper.

Structure of the new section

  1. The motivating "before" snippet — handler is async only because of the id lookup, pulls IDocumentSession in as infrastructure noise.
  2. Defining the strong-typed id and the GetNextReportId extension (uses Marten 8.31's NextSequenceValue).
  3. Implementing IVariableSourceMatches + Create, with a MethodCall frame so the async/dependency bookkeeping happens in generated code.
  4. Registering via opts.CodeGeneration.Sources.Add(...).
  5. Relationship to the A-Frame LoadAsync pattern — they coexist; IVariableSource is the right choice when the value is created, LoadAsync when it's retrieved.
  6. How to preview the generated code to confirm the source fired (codegen preview).
  7. Link out to the full runnable sample.

Closes

#2508

Test plan

  • docs/guide/codegen.md renders locally
  • CI docs build

🤖 Generated with Claude Code

Adds a "Custom Variable Sources" section to docs/guide/codegen.md
covering the pattern from the CritterStackSamples/Reports sample and
the April 20, 2026 blog post.

Walks through:

1. The motivating problem — handlers forced to be async and pick up an
   IDocumentSession dependency just to pull a sequence-generated id
   before creating an aggregate.

2. Defining the strong-typed id (ReportId) and an IDocumentSession
   extension that wraps Marten 8.31's NextSequenceValue helper.

3. Implementing IVariableSource (Matches + Create) using a MethodCall
   frame to teach Wolverine's codegen how to materialize the id.

4. Registering the source on WolverineOptions.CodeGeneration.Sources.

5. How the approach relates to the A-Frame LoadAsync pattern — both
   can coexist on the same handler; IVariableSource is the better fit
   when the value is newly created rather than loaded.

6. How to preview the generated code and confirm the source fired.

Links out to the full runnable sample at
https://github.com/JasperFx/CritterStackSamples/tree/main/Reports.

Doc-only change; no code or tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant