Repository navigation
[Mocha] Add DbContext.Outbox for atomic SaveChanges publishes - #10535
Draft
tobias-tengler wants to merge 8 commits into
Draft
tobias-tengler wants to merge 8 commits into
tobias-tengler wants to merge 8 commits into
Conversation
Contributor
Patch coverage96.5% of changed lines covered (718/744) +16 more changed files; see the JSON below for uncovered lines. Uncovered changed lines (JSON){
"sha": "3d292c0dedaabb45f11599a1eb81428f27cfafd1",
"files": [
{ "path": "src/Mocha/src/Mocha/Endpoints/DispatchEndpoint.cs", "ranges": [[74, 74], [78, 81], [83, 86], [187, 189]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore/DbContextAccessor.cs", "ranges": [[33, 36], [40, 40]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore/MessageBusHostBuilderExtensions.cs", "ranges": [[104, 104]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore/RegistrationThrowHelper.cs", "ranges": [[22, 22]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore/ThrowHelper.cs", "ranges": [[22, 22]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Outbox/OutboxServiceCollectionExtensions.cs", "ranges": [[111, 112], [129, 130]] },
{ "path": "src/Mocha/src/Mocha.EntityFrameworkCore/Outbox/DbContextOutbox.cs", "ranges": [[133, 134]] }
]
}Project coverage: 59.2% (314191/530331 lines) |
tobias-tengler
force-pushed
the
tte/outbox-unit-of-work
branch
from
October 16, 2026 08:54
9403cbd to
6409ccc
Compare
tobias-tengler
force-pushed
the
tte/outbox-unit-of-work
branch
4 times, most recently
from
October 19, 2026 07:18
06228cc to
987ad6b
Compare
tobias-tengler
changed the base branch from
main
to
tte/outbox-require-transaction
October 19, 2026 07:18
tobias-tengler
added this pull request to stack #10637
October 19, 2026 07:26
tobias-tengler
force-pushed
the
tte/outbox-unit-of-work
branch
2 times, most recently
from
October 21, 2026 09:38
632f33a to
c93557a
Compare
tobias-tengler
force-pushed
the
tte/outbox-unit-of-work
branch
from
October 21, 2026 14:49
ce75cfa to
0eb8145
Compare
tobias-tengler
force-pushed
the
tte/outbox-unit-of-work
branch
from
October 21, 2026 15:41
0eb8145 to
3f58253
Compare
This branch has not been deployed
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.
API endpoints and background services that rely on EF Core saves currently need to manage an explicit transaction to persist business changes and outbox messages together. Publishing separately can allow a message to escape a failed or omitted save.
This PR adds
await db.Outbox.PublishAsync(message, cancellationToken)to prepare messages for the DbContext's next save. DI-resolved contexts use the current application's or consumer's scoped bus, including when contexts are pooled, while factory registrations retain their configured lifetimes. Contexts created directly through a factory are not bound for this API. It handles message cleanup, save retries, synchronous saves after preparation, and asynchronous save interceptors; scheduled messages are rejected. It also prevents application clock skew from delaying new outbox rows and updates the reliability documentation and regression tests. Validation passed: 47 targeted PostgreSQL tests, the test project build with no warnings or errors, and documentation formatting.