Skip to content

Support projection side effects on Inline projections (#99)#101

Merged
jeremydmiller merged 1 commit into
mainfrom
feature/inline-side-effects-99
May 14, 2026
Merged

Support projection side effects on Inline projections (#99)#101
jeremydmiller merged 1 commit into
mainfrom
feature/inline-side-effects-99

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Promotes EnableSideEffectsOnInlineProjections from a hardcoded false to a configurable setting on EventGraph. When the flag is on:

  • RaiseSideEffects() runs for projections registered with the Inline lifecycle (the gate inside JFx.Events' projection bases reads IStorageOperations.EnableSideEffectsOnInlineProjections).
  • slice.PublishMessage(...) routes through the configured IMessageOutbox via a new GetOrStartMessageSink() impl on DocumentSessionBase, lazily creating an IMessageBatch on first publish and reusing it for the rest of the session's commit.
  • The session's SaveChangesInternalAsync calls BeforeCommitAsync on the message batch inside the SQL transaction (right before tx.CommitAsync) and AfterCommitAsync once after the commit + listeners have run.

slice.AppendEvent(...) from an inline RaiseSideEffects override is disallowed at the JFx.Events level (throws InvalidOperationException).

Test coverage in src/Polecat.Tests/Events/inline_projection_side_effects_tests.cs: flag-off no-op, flag-on publish round-trip, lifecycle ordering.

Promotes EnableSideEffectsOnInlineProjections from a hardcoded false to
a configurable setting on EventGraph. When the flag is on:

- RaiseSideEffects() runs for projections registered with the Inline
  lifecycle (the gate inside JFx.Events' projection bases reads
  IStorageOperations.EnableSideEffectsOnInlineProjections).
- slice.PublishMessage(...) routes through the configured IMessageOutbox
  via a new GetOrStartMessageSink() impl on DocumentSessionBase, lazily
  creating an IMessageBatch on first publish and reusing it for the
  rest of the session's commit.
- The session's SaveChangesInternalAsync calls BeforeCommitAsync on the
  message batch inside the SQL transaction (right before tx.CommitAsync)
  and AfterCommitAsync once after the commit + listeners have run.

slice.AppendEvent(...) from an inline RaiseSideEffects override is
disallowed at the JFx.Events level (throws InvalidOperationException).

Test coverage in src/Polecat.Tests/Events/inline_projection_side_effects_tests.cs:
flag-off no-op, flag-on publish round-trip, lifecycle ordering.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 647b3b9 into main May 14, 2026
6 checks passed
@jeremydmiller jeremydmiller deleted the feature/inline-side-effects-99 branch May 14, 2026 15:25
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