Skip to content

Enhance mediator functionality with manual handler registration#9452

Merged
PascalSenn merged 4 commits intomainfrom
pse/adds-manual-configuration-to-mediator
Mar 26, 2026
Merged

Enhance mediator functionality with manual handler registration#9452
PascalSenn merged 4 commits intomainfrom
pse/adds-manual-configuration-to-mediator

Conversation

@PascalSenn
Copy link
Copy Markdown
Member

@PascalSenn PascalSenn commented Mar 25, 2026

  • Introduced AddHandler<T>() method for manual registration of command, query, and notification handlers.
  • Updated documentation to reflect changes in handler registration and notification publish modes.
  • Added MediatorConfiguration, MediatorHandlerConfiguration, and MediatorHandlerKind classes for improved configuration management.
  • Implemented MediatorHandlerDescriptor for fluent API in handler configuration.
  • Added tests for manual handler registration and dispatching various command, query, and notification types.
  • Improved error handling for invalid handler types during registration.

…onfiguration options

- Introduced `AddHandler<T>()` method for manual registration of command, query, and notification handlers.
- Updated documentation to reflect changes in handler registration and notification publish modes.
- Added `MediatorConfiguration`, `MediatorHandlerConfiguration`, and `MediatorHandlerKind` classes for improved configuration management.
- Implemented `MediatorHandlerDescriptor` for fluent API in handler configuration.
- Added tests for manual handler registration and dispatching various command, query, and notification types.
- Improved error handling for invalid handler types during registration.
Copilot AI review requested due to automatic review settings March 25, 2026 20:18
@github-actions github-actions Bot added the 📚 documentation This issue is about working on our documentation. label Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Mocha Mediator handler registration to support manual AddHandler<T>() registration alongside source-generated registration, and replaces notification “strategy” types with a runtime NotificationPublishMode option (sequential vs concurrent). It also updates docs, tests, and analyzer snapshots to match the new configuration/registration model.

Changes:

  • Introduces descriptor/configuration-based handler registration (MediatorHandlerConfiguration, MediatorHandlerDescriptor, AddHandler<T>()) and updates pipeline building to use per-handler pipelines (especially for notifications).
  • Replaces notification strategy services with NotificationPublishMode in MediatorOptions, updating mediator publish behavior and tests accordingly.
  • Updates analyzer code generation to emit handler-configuration registrations (and updates snapshots), plus docs/benchmarks/solution file updates.

Reviewed changes

Copilot reviewed 78 out of 78 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
website/src/docs/mocha/v1/mediator/pipeline-and-middleware.md Updates pipeline/middleware and notification publish mode documentation.
website/src/docs/mocha/v1/mediator/index.md Documents manual AddHandler<T>() and options; minor wording tweaks.
src/Mocha/test/Mocha.Mediator.Tests/TestSetup.cs Refactors test service-provider setup to use handler registration APIs.
src/Mocha/test/Mocha.Mediator.Tests/NotificationStrategyTests.cs Updates tests to use NotificationPublishMode and AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/NamedMediatorTests.cs Updates named mediator tests to register handlers via AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/MiddlewarePipelineTests.cs Updates middleware tests to register handlers via AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/MiddlewareFactoryContextTests.cs Updates middleware factory context tests to use AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/InstrumentationTests.cs Updates instrumentation tests to use AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/ContextPoolingTests.cs Updates pooling tests to use AddHandler.
src/Mocha/test/Mocha.Mediator.Tests/AddHandlerTests.cs Adds coverage for manual handler registration and dispatch.
src/Mocha/test/Mocha.EntityFrameworkCore.Tests/EntityFrameworkTransactionMiddlewareTests.cs Updates EF transaction middleware tests to use AddHandler.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/WarmUpGeneratorTests.Generate_WarmUpMethod_WithAllHandlerTypes_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/QueryHandlerGeneratorTests.Generate_QueryHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/QueryHandlerGeneratorTests.Generate_MultipleQueryHandlers_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/PartialClassHandlerTests.Generate_PartialVoidCommandHandler_AcrossFiles_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/PartialClassHandlerTests.Generate_PartialQueryHandler_AcrossFiles_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/PartialClassHandlerTests.Generate_PartialClassHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/NotificationHandlerGeneratorTests.Generate_SingleNotificationHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/NotificationHandlerGeneratorTests.Generate_MultipleHandlersForSameNotification_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/NestedHandlerTests.Generate_NestedClassHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/ModuleNameHelperTests.Generate_NullAssemblyName_UsesAssemblyDefault_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/ModuleNameHelperTests.Generate_AssemblyNameWithHyphen_UsesLastSegmentSanitized_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/MixedHandlerGeneratorTests.Generate_HandlersInDifferentNamespaces_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/MixedHandlerGeneratorTests.Generate_AllHandlerTypes_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/MediatorModuleTests.Generate_ModuleFile_ContainsHandlerRegistrations.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/MediatorModuleTests.Generate_DottedAssemblyName_UsesLastSegment.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/MediatorModuleTests.Generate_DefaultAssemblyName_PrefixesWithLastSegment.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/KnownTypeSymbolsTests.Generate_WithAllHandlerTypes_AllSymbolsResolved_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/KnownTypeSymbolsTests.Generate_CommandVoidResolution_ICommandInterface_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/KnownTypeSymbolsTests.Generate_CommandOfTResolution_ICommandGeneric_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/InternalHandlerTests.Generate_InternalHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/GenericHandlerTests.Generate_OpenGenericCommand_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/GenericHandlerTests.Generate_MultipleHandlersSameNamespace_DeterministicOrder_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/ExplicitModuleNameTests.Generate_ModuleWithOnlyName_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/DiagnosticTests.NoWarning_CommandWithHandler_NoDiagnostic.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/DiagnosticTests.MO0004_OpenGenericQuery_ReportsInfo.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/DiagnosticTests.MO0004_OpenGenericCommand_ReportsInfo.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/DiagnosticTests.MO0002_VoidCommandWithTwoHandlers_ReportsError.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/DiagnosticTests.MO0002_CommandWithTwoHandlers_ReportsError.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/CommandHandlerGeneratorTests.Generate_VoidCommandHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/CommandHandlerGeneratorTests.Generate_MultipleCommandHandlers_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/test/Mocha.Analyzers.Tests/snapshots/CommandHandlerGeneratorTests.Generate_CommandWithResponseHandler_MatchesSnapshot.md Snapshot update for new handler-configuration generation output.
src/Mocha/src/Mocha/Transport/MessagingTransportDescriptor.cs Updates transport descriptor extension API types (but currently leaves ExtendWith methods as no-ops).
src/Mocha/src/Mocha/Descriptors/MessagingDescriptorBase.cs Renames descriptor extension interface and updates base implementation.
src/Mocha/src/Mocha/Descriptors/IMessagingDescriptorExtension.cs Renames/reshapes descriptor extension interfaces.
src/Mocha/src/Mocha/Descriptors/IMessagingDescriptor.cs Updates descriptor interfaces to return the renamed extension interface.
src/Mocha/src/Mocha.Mediator/Pipeline/TaskWhenAllPublisher.cs Removes old concurrent notification strategy implementation.
src/Mocha/src/Mocha.Mediator/Pipeline/PipelineBuilder.cs Replaces “terminal” builders with handler-typed pipeline builders.
src/Mocha/src/Mocha.Mediator/Pipeline/NotificationStrategyFeature.cs Removes old runtime feature holding INotificationStrategy.
src/Mocha/src/Mocha.Mediator/Pipeline/MediatorPipelineConfiguration.cs Removes old pipeline configuration model.
src/Mocha/src/Mocha.Mediator/Pipeline/ForeachAwaitPublisher.cs Removes old sequential notification strategy implementation.
src/Mocha/src/Mocha.Mediator/MediatorRuntime.cs Adds separate notification pipeline storage and exposes publish mode.
src/Mocha/src/Mocha.Mediator/MediatorOptions.cs Adds NotificationPublishMode option and enum.
src/Mocha/src/Mocha.Mediator/Mediator.cs Implements sequential vs concurrent notification dispatch over per-handler pipelines.
src/Mocha/src/Mocha.Mediator/Descriptors/MediatorHandlerDescriptor.cs Adds fluent handler descriptor with interface-based kind detection.
src/Mocha/src/Mocha.Mediator/Descriptors/MediatorDescriptorBase.cs Adds shared base for mediator descriptors/extensions.
src/Mocha/src/Mocha.Mediator/Descriptors/MediatorConfigurationContext.cs Adds internal configuration context for descriptor construction.
src/Mocha/src/Mocha.Mediator/Descriptors/IMediatorHandlerDescriptor.cs Adds handler descriptor interface.
src/Mocha/src/Mocha.Mediator/Descriptors/IMediatorDescriptorExtension.cs Adds mediator descriptor extension interfaces.
src/Mocha/src/Mocha.Mediator/Descriptors/IMediatorDescriptor.cs Adds mediator descriptor interfaces.
src/Mocha/src/Mocha.Mediator/Descriptors/IMediatorConfigurationContext.cs Adds mediator configuration context interface.
src/Mocha/src/Mocha.Mediator/Descriptors/IHasMediatorConfigurationContext.cs Adds context marker interface for descriptors/extensions.
src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorHostBuilderHandlerExtensions.cs Adds IMediatorHostBuilder.AddHandler<T>() and generator-only configuration hook.
src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorBuilder.cs Refactors runtime build around handler descriptors and per-handler notification pipelines.
src/Mocha/src/Mocha.Mediator/DependencyInjection/IMediatorBuilder.cs Replaces RegisterPipeline with handler registration/configuration APIs.
src/Mocha/src/Mocha.Mediator/Configuration/MediatorHandlerKind.cs Introduces handler kind enum for configuration.
src/Mocha/src/Mocha.Mediator/Configuration/MediatorHandlerConfiguration.cs Introduces handler configuration model used by generator/manual registration.
src/Mocha/src/Mocha.Mediator/Configuration/MediatorConfiguration.cs Adds base configuration with feature extensibility.
src/Mocha/src/Mocha.Mediator.Abstractions/INotificationStrategy.cs Removes old notification strategy abstraction.
src/Mocha/src/Mocha.Analyzers/Models/MessageKind.cs Renames void-command kind to Command.
src/Mocha/src/Mocha.Analyzers/Models/HandlerKind.cs Renames void-command handler kind to Command.
src/Mocha/src/Mocha.Analyzers/Inspectors/MessageTypeInspector.cs Updates kind inference for ICommand messages.
src/Mocha/src/Mocha.Analyzers/Inspectors/HandlerInspector.cs Updates kind inference for void command handlers.
src/Mocha/src/Mocha.Analyzers/Generators/DependencyInjectionGenerator.cs Updates generator to emit handler configuration registrations.
src/Mocha/src/Mocha.Analyzers/FileBuilders/DependencyInjectionFileBuilder.cs Rewrites generated output to use AddHandlerConfiguration + new pipeline builders.
src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Program.cs Updates benchmark target to net10.0 toolchain settings.
src/Mocha/benchmarks/Directory.Packages.props Adds central BenchmarkDotNet version for benchmarks.
src/Mocha/Mocha.slnx Adds mediator/analyzer projects to the solution listing.
Comments suppressed due to low confidence (1)

src/Mocha/src/Mocha/Transport/MessagingTransportDescriptor.cs:247

  • ExtendWith(...) currently ignores both the configure delegate and the state parameter, returning this without applying any configuration (and without null-checking). This will silently drop transport extensions that rely on this overload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/src/docs/mocha/v1/mediator/pipeline-and-middleware.md
Comment thread website/src/docs/mocha/v1/mediator/index.md Outdated
Comment thread src/Mocha/src/Mocha/Transport/MessagingTransportDescriptor.cs
Comment thread website/src/docs/mocha/v1/mediator/index.md Outdated
Comment thread website/src/docs/mocha/v1/mediator/index.md Outdated
Comment thread src/Mocha/src/Mocha.Mediator/Mediator.cs
Comment thread src/Mocha/src/Mocha.Mediator/Mediator.cs Outdated
Comment thread src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorBuilder.cs
Comment thread src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorBuilder.cs
@PascalSenn PascalSenn changed the title Enhance mediator functionality with manual handler registration and configuration options Enhance mediator functionality with manual handler registration Mar 26, 2026
@PascalSenn PascalSenn merged commit 755ce43 into main Mar 26, 2026
127 checks passed
@PascalSenn PascalSenn deleted the pse/adds-manual-configuration-to-mediator branch March 26, 2026 21:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (64dcf22) to head (5c8b9c7).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #9452   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants