Skip to content

v1.2.1: don't fold deliberately isolated scopes into the outer dispatch - #3

Merged
nifragos merged 2 commits into
mainfrom
fix/nested-dispatch-scope
Sep 13, 2026
Merged

nifragos merged 2 commits into
mainfrom
fix/nested-dispatch-scope

Conversation

@nifragos

Copy link
Copy Markdown
Contributor

Summary

With UseScopePerDispatch, 1.2.0 reused the in-flight dispatch scope for any nested Send/Publish. That included one made through a mediator resolved from a scope the handler had created on purpose to get its own DbContext, so the isolated work silently landed back on the outer DbContext.

Now only a mediator resolved from the in-flight scope (the ISender/IPublisher injected into a handler) joins it; any other mediator starts its own dispatch scope. Apps that don't call UseScopePerDispatch are unaffected.

  • Mediator.Dispatch: reuse only when _provider is the active dispatch scope
  • New test A_send_through_a_scope_the_handler_created_itself_is_not_folded_into_the_outer_dispatch
  • XML docs, README (scope-per-dispatch section) and CHANGELOG updated; version 1.2.1

This branch is based on docs/upgrading-to-1.2 (#2) because it adds a 1.2.1 entry to the changelog introduced there. Merge #2 first, or merge this and close #2.

Test plan

  • 60/60 tests pass on net10 locally; builds on net8/net9/net10 with warnings as errors
  • The new test fails against the 1.2.0 reuse rule (Assert.NotSame – same instance) and passes with the fix
  • Fabrica (the app that uses scope-per-dispatch) passes 176 application + 209 UI tests against a local 1.2.1 build, including nested-reuse and identity tests
  • CI on net8/net9/net10

…outer dispatch; v1.2.1

In 1.2.0, while a dispatch was in flight, any nested Send/Publish reused its
scope, including one made through a mediator resolved from a scope the handler
created itself to get its own DbContext. Only a mediator resolved from the
in-flight scope (the ISender/IPublisher injected into a handler) now joins it;
any other mediator starts its own dispatch scope.
@nifragos
nifragos merged commit 56a39cb into main Sep 13, 2026
2 checks passed
@nifragos
nifragos deleted the fix/nested-dispatch-scope branch September 13, 2026 15:11
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