Add UsingStore<T> declarative ancillary-store enrichment (supersedes #4301)#4313
Merged
Conversation
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>
This was referenced Apr 30, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IServiceProviderthroughStoreOptionsand exposes it onIStorageOperations.Servicesso the newEntityStep<TEntity>.UsingStore<TStore>()instance method shipped in JasperFx.Events 1.31 can resolve ancillaryIDocumentStoretypes from DI at enrichment time.Lazy<TStore>overload (AncillaryStoreEnrichmentExtensions.UsingStore) for projections that already hold aLazy<>reference and want to opt out of DI lookup.ancillary_store_enrichment_tests.enrichment_from_ancillary_store_resolves_entity_and_maps_to_projectionexercises the full path: a primary store projection enrichesOrderPlacedevents withProductdata fetched from a separate ancillary store registered viaAddMartenStore<IProductStore>.Closes #4300. Closes #4301.
Notes for reviewers
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 underlyingUsingStore<TStore>()instance method).Servicessetter onStoreOptions/SecondaryStoreConfigis new public-adjacent surface, and it isinternal.Test plan
dotnet build src/Marten.sln— 0 errorsdotnet test src/EventSourcingTests --filter "FullyQualifiedName~ancillary_store_enrichment_tests" -f net9.0— passes locally🤖 Generated with Claude Code