v3/feature/215: Pluggable Notification Publish Strategies#232
Merged
Conversation
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)
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.
Changes
New files:
Modified files:
Tests — NotificationPublishStrategyTests.cs (13 tests):