Mediator Pattern Guide
Reduce coupling between components by centralizing their communication through a mediator object. Instead of objects referencing each other directly, they communicate through the mediator, simplifying dependencies.
Usage
Ask about implementing the mediator pattern, using it with CQRS command handlers, or reducing coupling in complex UI or service interactions.
Examples
- "How do I implement a mediator for my CQRS command handlers?"
- "When should I use mediator pattern vs direct method calls?"
- "Help me reduce coupling between my UI components with a mediator"
Guidelines
- Use mediator when many objects communicate in complex ways
- The mediator should orchestrate, not contain business logic
- Avoid creating a god-object mediator that knows too much
- Combine with command pattern for clean request handling pipelines
- Consider using an existing library like MediatR instead of building from scratch