Evaluate the EF Core persistence provider before Marten regardless of registration order#3361
Merged
Merged
Conversation
… registration order (#3359) In mixed Marten + EF Core applications, which provider owned an entity for storage actions, [Entity] loading, and saga persistence depended on the order the two integrations were registered in Program.cs. Two root causes: 1. MartenPersistenceFrameProvider.CanPersist claims every type (Marten can genuinely persist any document) and TryFindPersistenceFrameProvider takes candidates.First(), so whichever integration registered last sat at index 0 via InsertFirstPersistenceStrategy and won everything. 2. AddDbContextWithWolverineIntegration registered its extension with TryAddSingleton<IWolverineExtension, ...>, which gates on the service type alone - if any other integration (e.g. Marten's IntegrateWithWolverine) had already registered an IWolverineExtension, the EF Core codegen integration was silently never registered at all. Fixes: - New IPersistenceFrameProvider.IsCatchAll default-interface member. Catch-all document stores (Marten, Polecat, RavenDb, CosmosDb, in-memory) override it to true; selective providers like EF Core (which only claims types mapped in a registered DbContext model) stay false. - TryFindPersistenceFrameProvider, GetPersistenceProviders, SagaPersistenceChainPolicy, and the capabilities saga tagger now consult providers via OrderedPersistenceProviders(): selective providers first, catch-alls last, stable within each group. - AddDbContextWithWolverineIntegration uses TryAddEnumerable so its extension registration dedupes on the (service, implementation) pair instead of being swallowed by any pre-existing IWolverineExtension. Verification: new registration-order permutation tests in PersistenceTests fail on both permutations without the fix and pass with it; 5 new CoreTests unit tests for the ordering primitive; CoreTests 1905/0, EfCoreTests 186/187 (known Bug_1846 load flake), PersistenceTests 68/69 (known pre-existing using_dynamic_multi_tenancy full-suite flake, passes in isolation); full wolverine.slnx Release build 0 warnings / 0 errors. Closes #3359 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 10, 2026
This was referenced Jul 14, 2026
This was referenced Jul 18, 2026
Open
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.
Closes #3359. Follow-up to #3353/#3357.
In a mixed Marten + EF Core application, which persistence provider owned an entity for storage actions,
[Entity]loading, and saga persistence silently depended on the order the two integrations were registered inProgram.cs. Writing the registration-order permutation tests surfaced two root causes, not one:MartenPersistenceFrameProvider.CanPersistclaims every type (Marten genuinely can persist any document) andTryFindPersistenceFrameProvidertakescandidates.First()— so whichever integration registered last sat at index 0 viaInsertFirstPersistenceStrategyand claimed everything, including EF-mapped entities.AddDbContextWithWolverineIntegrationregistered its Wolverine extension withTryAddSingleton<IWolverineExtension, …>, which gates on the service type alone. If any other integration (e.g. Marten'sIntegrateWithWolverine()) had already registered anIWolverineExtension, the EF Core codegen integration — persistence provider, batching policy, query-spec policy — was never registered at all. This went unnoticed becauseUseEntityFrameworkCoreTransactions()applies the same extension eagerly viaoptions.Include<>(); only apps relying onAddDbContextWithWolverineIntegrationalone were bitten.Changes
IPersistenceFrameProvider.IsCatchAlldefault-interface member (defaultfalse). The catch-all document stores override it totrue: Marten, Polecat, RavenDb, CosmosDb, and the in-memory provider. EF Core stays selective — it only claims types actually mapped in a registeredDbContextmodel.GenerationRulesExtensions.OrderedPersistenceProviders(): selective providers first, catch-alls last, registration order preserved within each group (stable sort). Consumed byTryFindPersistenceFrameProvider,GetPersistenceProviders,SagaPersistenceChainPolicy, and the service-capabilities saga tagger (which documents that it mirrors the codegen precedence).AutoApplyTransactionsis untouched — it already only applies when exactly one provider matches.AddDbContextWithWolverineIntegrationnow usesTryAddEnumerable(ServiceDescriptor.Singleton<IWolverineExtension, EntityFrameworkCoreBackedPersistence>()), which dedupes on the (service, implementation) pair — idempotent across repeated calls without being swallowed by other integrations' extensions.With EF Core first, EF-mapped entities deterministically resolve to their
DbContextand every other document still falls through to Marten — nothing only Marten can persist is taken away from it.Tests
PersistenceTests.persistence_provider_precedence_permutations: Marten-then-EFCore and EFCore-then-Marten hosts, each asserting anItemmapped inSampleDbContextresolves toEFCorePersistenceFrameProviderand an unmapped document resolves toMartenPersistenceFrameProvider. Red-first verified: with the production changes stashed, both permutations fail (one via ordering, one via the swallowed registration).CoreTests.Persistence.persistence_provider_precedence: 5 unit tests for the ordering primitive with fake selective/catch-all providers, including stable-order-within-group.Verification
Bug_1846load-flake; passes isolated)using_dynamic_multi_tenancyis a pre-existing full-suite flake — it also fails on unfixed baseline binaries and passes in isolation)wolverine.slnxRelease build: 0 warnings / 0 errors🤖 Generated with Claude Code