Skip to content

Support FromMethod on WriteAggregate for custom ID resolution#2458

Merged
jeremydmiller merged 1 commit into
mainfrom
2451-write-aggregate-from-method
Apr 8, 2026
Merged

Support FromMethod on WriteAggregate for custom ID resolution#2458
jeremydmiller merged 1 commit into
mainfrom
2451-write-aggregate-from-method

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Summary

  • [WriteAggregate] now supports FromMethod, FromRoute, FromHeader, and FromClaim for custom aggregate ID resolution, matching the existing behavior of [ReadAggregate]
  • The fix is minimal: when a specific ValueSource has been set (e.g. via FromMethod), the inherited tryFindIdentityVariable() is used first, which respects the ValueSource property. Falls back to the existing FindIdentity() logic for full backward compatibility.

Example

public static class WriteAggregateFromMethodEndpoint
{
    public static Guid ResolveOrderId(ClaimsPrincipal user)
    {
        var claim = user.FindFirstValue("order-id");
        return claim != null ? Guid.Parse(claim) : Guid.Empty;
    }

    [WolverinePost("/orders/confirm-from-method"), EmptyResponse]
    public static OrderConfirmed Post(
        ConfirmOrderFromMethod command,
        [WriteAggregate(FromMethod = nameof(ResolveOrderId))] Order order)
    {
        return new OrderConfirmed();
    }
}

Closes #2451

Test plan

  • All 619 Wolverine.Http.Tests pass (0 failures)
  • 3 new integration tests: write with FromMethod, read with FromMethod, 404 on missing aggregate
  • Verified backward compatibility — existing WriteAggregate behavior unchanged

🤖 Generated with Claude Code

WriteAggregateAttribute.FindIdentity() hardcoded ValueSource.Anything,
ignoring the ValueSource property set by FromMethod and other base class
properties. Now checks if a specific ValueSource has been set and uses
the inherited tryFindIdentityVariable() which respects it, falling back
to the existing FindIdentity() logic for backward compatibility.

Closes #2451

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 776ac28 into main Apr 8, 2026
16 of 19 checks passed
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.

WriteAggregate does not support FromMethod static ID resolution

1 participant