Skip to content

v3/feature/215: Pluggable Notification Publish Strategies#232

Merged
eneshoxha merged 1 commit into
v3.2/releasefrom
v3/feature/215
Feb 24, 2026
Merged

v3/feature/215: Pluggable Notification Publish Strategies#232
eneshoxha merged 1 commit into
v3.2/releasefrom
v3/feature/215

Conversation

@eneshoxha

Copy link
Copy Markdown
Contributor

Changes

New files:

  • Notifications/INotificationPublishStrategy.cs — Interface with a single PublishAsync(IEnumerable<Func>, CancellationToken) method. Strategies receive pre-built handler pipeline delegates and decide how to execute them.
  • Notifications/ParallelNotificationStrategy.cs — Default strategy. Executes all handlers in parallel via Task.WhenAll (preserves current behavior).
  • Notifications/SequentialNotificationStrategy.cs — Executes handlers one at a time in registration order. Respects cancellation between handlers.
  • Notifications/StopOnFirstFailureNotificationStrategy.cs — Sequential execution that stops immediately on first exception, skipping remaining handlers.

Modified files:

  • MediatorOptions.cs — Added NotificationPublishStrategyType (internal) and UseNotificationPublishStrategy() fluent method. Default is ParallelNotificationStrategy.
  • ServiceCollectionExtensions.cs — Registers INotificationPublishStrategy as singleton from the configured type.
  • Mediator.cs — Refactored PublishAsync to build Func[] delegates and delegate execution to INotificationPublishStrategy. Falls back to parallel when no strategy is registered (backward compatible for manual DI).

Tests — NotificationPublishStrategyTests.cs (13 tests):

  • Default strategy is Parallel
  • UseNotificationPublishStrategy DI registration
  • Fluent API returns options
  • Parallel: all handlers execute, exceptions propagate
  • Sequential: order preserved, stops on exception, respects cancellation
  • StopOnFirstFailure: all succeed case, stops on first exception
  • Integration with AddCortexMediator
  • Fallback when no strategy registered
  • Custom strategy support (reverse order strategy)

  Changes

  New files:

  - Notifications/INotificationPublishStrategy.cs — Interface with a single PublishAsync(IEnumerable<Func<Task>>, CancellationToken) method. Strategies receive pre-built handler pipeline delegates and
  decide how to execute them.
  - Notifications/ParallelNotificationStrategy.cs — Default strategy. Executes all handlers in parallel via Task.WhenAll (preserves current behavior).
  - Notifications/SequentialNotificationStrategy.cs — Executes handlers one at a time in registration order. Respects cancellation between handlers.
  - Notifications/StopOnFirstFailureNotificationStrategy.cs — Sequential execution that stops immediately on first exception, skipping remaining handlers.

  Modified files:

  - MediatorOptions.cs — Added NotificationPublishStrategyType (internal) and UseNotificationPublishStrategy<TStrategy>() fluent method. Default is ParallelNotificationStrategy.
  - ServiceCollectionExtensions.cs — Registers INotificationPublishStrategy as singleton from the configured type.
  - Mediator.cs — Refactored PublishAsync<TNotification> to build Func<Task>[] delegates and delegate execution to INotificationPublishStrategy. Falls back to parallel when no strategy is registered
  (backward compatible for manual DI).

  Tests — NotificationPublishStrategyTests.cs (13 tests):
  - Default strategy is Parallel
  - UseNotificationPublishStrategy DI registration
  - Fluent API returns options
  - Parallel: all handlers execute, exceptions propagate
  - Sequential: order preserved, stops on exception, respects cancellation
  - StopOnFirstFailure: all succeed case, stops on first exception
  - Integration with AddCortexMediator
  - Fallback when no strategy registered
  - Custom strategy support (reverse order strategy)
@eneshoxha eneshoxha added this to the Cortex v3.2 milestone Feb 24, 2026
@eneshoxha eneshoxha self-assigned this Feb 24, 2026
@eneshoxha eneshoxha added the feature This label is in use for minor version increments label Feb 24, 2026
@eneshoxha eneshoxha linked an issue Feb 24, 2026 that may be closed by this pull request
@eneshoxha eneshoxha merged commit 52dcb94 into v3.2/release Feb 24, 2026
@eneshoxha eneshoxha deleted the v3/feature/215 branch February 24, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature This label is in use for minor version increments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Pluggable Notification Publish Strategies

1 participant