Refactor mocha middleware to use unified Use method with optional positioning parameters#9419
Conversation
…ositioning parameters
There was a problem hiding this comment.
Pull request overview
This PR refactors Mocha (message bus + transports + mediator) middleware registration APIs to use a unified Use* method with optional before / after positioning, and updates docs + tests to reflect the new API surface.
Changes:
- Replace
Append*/Prepend*middleware registration APIs withUse*(..., before:/after:)across bus, transport, and endpoint descriptors. - Update Mocha.Mediator builder/host-builder middleware positioning to use
Use(..., before:/after:). - Update docs and tests to use the new unified API.
Reviewed changes
Copilot reviewed 46 out of 46 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/docs/mocha/v1/transports/index.md | Updates transport middleware ordering examples to UseReceive/UseDispatch with before/after. |
| website/src/docs/mocha/v1/reliability.md | Updates consumer middleware positioning example to UseConsume(..., before: "Inbox"). |
| website/src/docs/mocha/v1/middleware-and-pipelines.md | Rewrites ordering docs to describe the unified Use* API and positioning rules. |
| website/src/docs/mocha/v1/mediator/pipeline-and-middleware.md | Updates mediator middleware positioning docs and examples to Use(..., before:/after:). |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/TransportMiddlewareTests.cs | Renames/updates transport-level middleware ordering tests to the new Use* API. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/InboxTests.cs | Updates inbox-related tests to use UseDispatch/UseConsume with before. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/EndpointMiddlewareTests.cs | Updates endpoint-scoped middleware ordering tests to the new Use* API. |
| src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/TransportMiddlewareTests.cs | Renames/updates transport-level middleware ordering tests to the new Use* API. |
| src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/EndpointMiddlewareTests.cs | Updates endpoint-scoped middleware ordering tests to the new Use* API. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/InboxTests.cs | Updates in-memory inbox tests to use UseDispatch/UseConsume with before. |
| src/Mocha/test/Mocha.Tests/Outbox/OutboxIntegrationTests.cs | Updates outbox integration test middleware positioning to UseDispatch(..., before: "Outbox"). |
| src/Mocha/test/Mocha.Tests/Inbox/InboxIntegrationTests.cs | Updates inbox integration test middleware positioning to UseConsume(..., before: "Inbox"). |
| src/Mocha/src/Mocha/Transport/MessagingTransportDescriptor.cs | Consolidates transport middleware APIs into UseDispatch/UseReceive with optional before/after. |
| src/Mocha/src/Mocha/Endpoints/Descriptors/ReceiveEndpointDescriptor.cs | Consolidates endpoint receive middleware APIs into UseReceive with optional before/after. |
| src/Mocha/src/Mocha/Endpoints/Descriptors/IReceiveEndpointDescriptor.cs | Updates endpoint receive middleware interface to the unified UseReceive signature. |
| src/Mocha/src/Mocha/Endpoints/Descriptors/IDispatchEndpointDescriptor.cs | Updates endpoint dispatch middleware interface to the unified UseDispatch signature. |
| src/Mocha/src/Mocha/Endpoints/Descriptors/DispatchEndpointDescriptor.cs | Consolidates endpoint dispatch middleware APIs into UseDispatch with optional before/after. |
| src/Mocha/src/Mocha/Consumers/Descriptors/IConsumerDescriptor.cs | Consolidates consumer middleware APIs into UseConsumer with optional before/after. |
| src/Mocha/src/Mocha/Consumers/Descriptors/ConsumerDescriptor.cs | Implements unified UseConsumer behavior with positional insertion rules. |
| src/Mocha/src/Mocha/Builder/MessageBusBuilder.Middlewares.cs | Consolidates bus-level middleware registration into unified UseConsume/UseReceive/UseDispatch. |
| src/Mocha/src/Mocha/Abstractions/IMessageBusBuilder.cs | Replaces append/prepend methods with unified Use* signatures at the public abstraction level. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/Extensions/RabbitMQTransportDescriptorExtensions.cs | Updates RabbitMQ default middleware registration to use UseReceive(..., after: ...). |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/RabbitMQReceiveEndpointDescriptor.cs | Updates RabbitMQ receive endpoint descriptor to forward unified UseReceive. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/RabbitMQMessagingTransportDescriptor.cs | Updates RabbitMQ transport descriptor to forward unified UseDispatch/UseReceive. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/RabbitMQDispatchEndpointDescriptor.cs | Updates RabbitMQ dispatch endpoint descriptor to forward unified UseDispatch. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/IRabbitMQReceiveEndpointDescriptor.cs | Updates RabbitMQ receive endpoint interface to unified UseReceive signature. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/IRabbitMQMessagingTransportDescriptor.cs | Updates RabbitMQ transport interface to unified UseDispatch/UseReceive signatures. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/IRabbitMQDispatchEndpointDescriptor.cs | Updates RabbitMQ dispatch endpoint interface to unified UseDispatch signature. |
| src/Mocha/src/Mocha.Transport.Postgres/Topology/Extensions/PostgresTransportDescriptorExtensions.cs | Updates Postgres default middleware registration to use UseReceive(..., after: ...). |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/PostgresReceiveEndpointDescriptor.cs | Updates Postgres receive endpoint descriptor to forward unified UseReceive. |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/PostgresMessagingTransportDescriptor.cs | Updates Postgres transport descriptor to forward unified UseDispatch/UseReceive. |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/PostgresDispatchEndpointDescriptor.cs | Updates Postgres dispatch endpoint descriptor to forward unified UseDispatch. |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/IPostgresReceiveEndpointDescriptor.cs | Updates Postgres receive endpoint interface to unified UseReceive signature. |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/IPostgresMessagingTransportDescriptor.cs | Updates Postgres transport interface to unified UseDispatch/UseReceive signatures. |
| src/Mocha/src/Mocha.Transport.Postgres/Descriptors/IPostgresDispatchEndpointDescriptor.cs | Updates Postgres dispatch endpoint interface to unified UseDispatch signature. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/InMemoryReceiveEndpointDescriptor.cs | Updates in-memory receive endpoint descriptor to forward unified UseReceive. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/InMemoryMessagingTransportDescriptor.cs | Updates in-memory transport descriptor to forward unified UseDispatch/UseReceive. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/InMemoryDispatchEndpointDescriptor.cs | Updates in-memory dispatch endpoint descriptor to forward unified UseDispatch. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/IInMemoryReceiveEndpointDescriptor.cs | Updates in-memory receive endpoint interface to unified UseReceive signature. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/IInMemoryMessagingTransportDescriptor.cs | Updates in-memory transport interface to unified UseDispatch/UseReceive signatures. |
| src/Mocha/src/Mocha.Transport.InMemory/Descriptors/IInMemoryDispatchEndpointDescriptor.cs | Updates in-memory dispatch endpoint interface to unified UseDispatch signature. |
| src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorHostBuilderExtensions.cs | Collapses mediator host-builder middleware methods into Use(..., before:/after:). |
| src/Mocha/src/Mocha.Mediator/DependencyInjection/MediatorBuilder.cs | Implements Use(..., before:/after:) and changes missing-key behavior to throw. |
| src/Mocha/src/Mocha.Mediator/DependencyInjection/IMediatorBuilder.cs | Updates mediator builder interface to unified Use signature with before/after. |
| src/Mocha/src/Mocha.Inbox/InboxCoreServiceCollectionExtensions.cs | Changes inbox core middleware registration from append-style to UseConsume. |
| src/Mocha/src/Examples/Middleware/CustomMiddleware/CustomMiddleware.cs | Updates example to the new middleware registration API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9419 +/- ##
==========================================
- Coverage 74.16% 0 -74.17%
==========================================
Files 2677 0 -2677
Lines 140790 0 -140790
Branches 16371 0 -16371
==========================================
- Hits 104421 0 -104421
+ Misses 30774 0 -30774
+ Partials 5595 0 -5595
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.