Skip to content

GH-5160: WolverineHttpOptions.DefaultClaimInTransaction, a global opt-in for [DeduplicatedWithResponse(ClaimInTransaction)] - #5173

Merged
jeremydmiller merged 1 commit into
mainfrom
gh-5160-claim-in-transaction-default
Oct 23, 2026
Merged

jeremydmiller merged 1 commit into
mainfrom
gh-5160-claim-in-transaction-default

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

This follows up #5169, and answers @uniquelau's question on #5161: ClaimInTransaction stays opt-in, and an application can now opt in once.

app.MapWolverineEndpoints(opts =>
{
    opts.DefaultClaimInTransaction = true;
});
  • An endpoint that doesn't set ClaimInTransaction takes the application default. That default is false, so nothing changes unless you set it.
  • An endpoint that sets it, either way, keeps its own choice. [DeduplicatedWithResponse(DeduplicationScope.User, ClaimInTransaction = false)] stays on claim-and-release even when the default is on.

How

This copies the existing DefaultDuplicateStatusCode / [Deduplicated(DuplicateStatusCode)] pattern (and EntityDefaults.OnMissing on [Entity]):

  • DeduplicatedWithResponseAttribute.ClaimInTransaction is backed by a bool?, which stays null until it is set. The public property still reads false when unset.
  • DeduplicatedWithResponseRequirement gets an internal ExplicitClaimInTransaction, alongside ExplicitDuplicateStatusCode. ToString() shows only an explicit choice.
  • WolverineHttpOptions.DefaultClaimInTransaction is copied onto HttpGraph in DiscoverEndpoints. The chain resolves requirement.ExplicitClaimInTransaction ?? _parent.DefaultClaimInTransaction when it is woven.
  • Fallback logging: an endpoint that can't take the transactional path (another store, database per tenant, UpdatedAggregate, ...) still falls back to claim-and-release.
    • If the endpoint asked for ClaimInTransaction itself, the fallback is still a warning.
    • If it only inherited the global default, it's logged at debug level. Otherwise every EF Core or no-commit endpoint would warn at startup.

No breaking changes: ClaimInTransaction came in with #5169 and hasn't shipped in a release yet. Its public shape is unchanged.

Tests

deduplicated_with_response_claim_in_transaction_default uses its own host with DefaultClaimInTransaction = true:

  • An endpoint that leaves the attribute unset takes the default. Its generated code queues the claim on the session, and a repeat replays.
  • An endpoint with ClaimInTransaction = false keeps claim-and-release.
  • An endpoint with ClaimInTransaction = true claims in the transaction.
  • Attribute-level checks: unset gives a null ExplicitClaimInTransaction; false gives an explicit false.

Mutation check: when the chain ignores the global default, the "unset" test fails.

Run locally:

  • Wolverine.Http.Tests, every deduplication test plus the new class: 106/106
  • dotnet build wolverine.slnx -c Release -f net9.0: 0 errors

Docs: docs/guide/http/deduplication.md has a new "Turning it on for every endpoint" section, with mdsnippets samples taken from the test.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DCggXgxnG3EBXoR9rrq37U

…on-wide default for [DeduplicatedWithResponse(ClaimInTransaction)]

ClaimInTransaction stays opt-in, and an application can now opt in once. An
endpoint that doesn't set ClaimInTransaction on its attribute takes
WolverineHttpOptions.DefaultClaimInTransaction (default false). One that sets it,
true or false, keeps its own choice. Same shape as DefaultDuplicateStatusCode for
[Deduplicated]: a nullable backing field on the attribute, an internal
ExplicitClaimInTransaction on the requirement, and the option carried onto HttpGraph.

An endpoint that can't take the transactional path still falls back to
claim-and-release. When it only inherited the default, that's logged at debug
level instead of as a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCggXgxnG3EBXoR9rrq37U
@jeremydmiller
jeremydmiller merged commit fba1afb into main Oct 23, 2026
48 checks passed
This was referenced Oct 25, 2026
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