Skip to content

Add source generator discovery for natural key aggregates#172

Merged
jeremydmiller merged 2 commits intomainfrom
fix/natural-key-source-gen-discovery
Mar 27, 2026
Merged

Add source generator discovery for natural key aggregates#172
jeremydmiller merged 2 commits intomainfrom
fix/natural-key-source-gen-discovery

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

  • New NaturalKeyAggregateAttribute emitted by the source generator when a self-aggregating type has a [NaturalKey] property
  • AggregateAnalyzer detects [NaturalKey] properties and sets HasNaturalKey on CandidateInfo
  • EvolverCodeEmitter emits [assembly: NaturalKeyAggregate(typeof(T))] alongside the existing GeneratedEvolver attribute
  • Enables Marten to auto-register snapshot projections at startup for natural key types (fixes Npgsql.PostgresException when using FetchForWriting() with natural keys marten#4199)

Test plan

  • JasperFx.Events and JasperFx.Events.SourceGenerator compile cleanly
  • Consumed by Marten fix for #4199 — 27/27 natural key tests pass

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits March 27, 2026 12:51
New NaturalKeyAggregateAttribute emitted by the source generator when a
self-aggregating type has a [NaturalKey] property. This allows Marten to
auto-register the snapshot projection and natural key infrastructure at
startup without requiring explicit Projections.Snapshot<T>(Inline) calls.

- AggregateAnalyzer: detect [NaturalKey] properties on aggregate types
- EvolverCodeEmitter: emit [assembly: NaturalKeyAggregate(typeof(T))]
- NaturalKeyAggregateAttribute: assembly-level marker for discovery

Fixes JasperFx/marten#4199

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- JasperFx 1.21.4 → 1.21.5
- JasperFx.Events 1.24.1 → 1.24.2 (new NaturalKeyAggregateAttribute)
- JasperFx.Events.SourceGenerator 1.3.0 → 1.4.0 (natural key discovery)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit b465869 into main Mar 27, 2026
1 check passed
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.

Npgsql.PostgresException when using FetchForWriting() with natural keys

1 participant