Skip to content

Add UsingStore<T> declarative ancillary-store enrichment (supersedes #4301)#4313

Merged
jeremydmiller merged 2 commits into
masterfrom
supersede-pr-4301-using-store
Apr 28, 2026
Merged

Add UsingStore<T> declarative ancillary-store enrichment (supersedes #4301)#4313
jeremydmiller merged 2 commits into
masterfrom
supersede-pr-4301-using-store

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

  • Supersedes Add UsingStore<T> declarative enrichment from ancillary stores (#4300) #4301 by Anne Erdtsieck (@erdtsieck), rebased onto current master (JasperFx 1.28.1 / JasperFx.Events 1.31.0). Original authorship preserved.
  • Plumbs IServiceProvider through StoreOptions and exposes it on IStorageOperations.Services so the new EntityStep<TEntity>.UsingStore<TStore>() instance method shipped in JasperFx.Events 1.31 can resolve ancillary IDocumentStore types from DI at enrichment time.
  • Adds a Lazy<TStore> overload (AncillaryStoreEnrichmentExtensions.UsingStore) for projections that already hold a Lazy<> reference and want to opt out of DI lookup.
  • New end-to-end test ancillary_store_enrichment_tests.enrichment_from_ancillary_store_resolves_entity_and_maps_to_projection exercises the full path: a primary store projection enriches OrderPlaced events with Product data fetched from a separate ancillary store registered via AddMartenStore<IProductStore>.

Closes #4300. Closes #4301.

Notes for reviewers

  • The diff is intentionally identical to what landed in Add UsingStore<T> declarative enrichment from ancillary stores (#4300) #4301 modulo (a) a missing using Marten.Events.Aggregation; directive added to the test file, and (b) the rebase onto master (which now pins JasperFx.Events 1.31.0 — the version that ships the underlying UsingStore<TStore>() instance method).
  • All existing event-sourcing tests continue to compile and run; only the small Services setter on StoreOptions/SecondaryStoreConfig is new public-adjacent surface, and it is internal.

Test plan

  • dotnet build src/Marten.sln — 0 errors
  • dotnet test src/EventSourcingTests --filter "FullyQualifiedName~ancillary_store_enrichment_tests" -f net9.0 — passes locally
  • Full CI green

🤖 Generated with Claude Code

erdtsieck and others added 2 commits April 28, 2026 17:17
Plumbs IServiceProvider through StoreOptions and IStorageOperations.Services
so the JasperFx.Events 1.31 EntityStep<TEntity>.UsingStore<TStore>() built-in
can resolve ancillary IDocumentStore types from DI at enrichment time. Adds
a Lazy<TStore> overload (AncillaryStoreEnrichmentExtensions.UsingStore) for
projections that already hold a Lazy<> reference, plus an end-to-end test
demonstrating projection enrichment from a separate ancillary store.

Supersedes #4301 — rebased onto current master (JasperFx 1.28.1 /
JasperFx.Events 1.31.0). Original work by Anne Erdtsieck.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
LinqTests.Acceptance shares a Target[] dataset built from the static
Target.GenerateRandomData helper. That helper consumes a process-wide
Random(67) which other tests in the same assembly may have already
advanced. When the LinqTests fixture happened to land on an unlucky
slice of that sequence, we'd see two related flakes:

- select_clauses: SelectTransform.Compare picks the first Target with
  StringArray.Length > 0, NumberArray.Length > 0, and Inner != null.
  If no document matched, target was null and line 27 NRE'd through
  every select_clauses theory.
- take_and_skip: OrderBy(x => x.Long).Skip(N).Take(M) compared against
  Postgres ORDER BY which is unstable on Long ties; non-deterministic
  data occasionally produced a tie.

Calling Target.ResetRandomSeed() in the fixture constructor before
generating Documents/FSharpDocuments makes the dataset stable seed-67
data: 0 Long-value collisions across 1000 docs and 3 select_clauses-
eligible Targets. Continues the flake-stabilization work from #4310 /
#4311.

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.

Feature: Declarative ancillary store enrichment via UsingStore<T>() in the enrich API

2 participants