fix(domain-events): correct payload guidance — keep events serializable#12734
Open
bradystroud wants to merge 1 commit into
Open
fix(domain-events): correct payload guidance — keep events serializable#12734bradystroud wants to merge 1 commit into
bradystroud wants to merge 1 commit into
Conversation
Replaces the claim that the entire entity/aggregate can be included in a domain event with concrete guidance that payloads should be primitives and IDs only. Adds bad/good code examples and rationale tied to the Transactional Outbox Pattern, event sourcing, and promotion to Integration Events — all of which require JSON serialization that aggregate roots are not built for.
Contributor
🔍 Preview PR ChangesView updated pages in edit mode:
|
Contributor
|
👋 Hi @bradystroud, This PR is currently in Draft mode. To help it get reviewed and merged:
Once you've completed these steps, your PR will be ready for approval! This is an automated reminder to help reduce draft PRs without descriptions or reviewers. |
Contributor
|
Howzit @bradystroud, This PR has been here a while. Did you know you should avoid merge debt?
Thanks! |
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.
While auditing a project's internal rules compare against SSW Rules, I noticed this rule advises "the entire Entity or Aggregate can be included since the event's scope is confined to the current bounded context."
We learned the hard way that this guidance doesn't hold up once an Outbox (or any async/persisted event handler) is introduced. Events holding an aggregate root fail to deserialize with
System.NotSupportedException: Deserialization of types without a parameterless constructor... is not supported, because aggregate roots typically have factory methods,private set/initproperties, and EF Core navigation properties. Events get stuck in the outbox and never publish.The same problem affects event sourcing, audit replay, and promotion to Integration Events — anything that requires JSON serialization.
In
public/uploads/rules/when-to-use-domain-and-integration-events/rule.mdx:## Event payloads — keep them serializablesection with:csharpexamples — bad passes the aggregate, good passes flat primitives + IDs + enums-as-int.Bounded-context greybox kept; Integration Events section untouched; frontmatter unchanged (
lastUpdated/lastUpdatedByare system-managed).Frontmatter validates clean via
scripts/frontmatter-validator.🤖 Drafted with Claude Code