Mediator Roadmap

This page summarizes the current and planned capabilities for the Mediator library. This roadmap focuses on high-signal planning items and provides visibility into the evolution of the mediator pattern implementation.

Legend

βœ… Implemented Β· πŸ”„ In Progress Β· ⭐ High Priority (next 1–2 milestones) Β· πŸ“‹ Planned Β· πŸ€” Considering

Phase Overview

  1. Foundation (βœ… complete)
  2. Core Request/Event Handling (βœ… complete)
  3. Pipeline Behaviors & Orchestration (βœ… complete)
  4. Source Generation & DI Integration (βœ… complete)
  5. Advanced Event Patterns (πŸ”„ outbox refinement, distributed events)
  6. Performance & Scalability (⭐ streaming, batching, caching)
  7. Observability & Diagnostics (πŸ“‹ tracing, metrics, debugging)
  8. Resilience & Error Recovery (πŸ“‹ retry policies, circuit breakers)
  9. Advanced Composition (πŸ“‹ saga patterns, distributed transactions)
  10. Tooling & Developer Experience (πŸ“‹ analyzers, testing utilities)

Recently Completed Highlights

  • Request/response pattern with ISender returning Result<TResponse> or Result
  • Event publishing with IPublisher supporting multiple handlers per event
  • Pipeline behaviors for both requests (IRequestPipelineBehavior) and events (IEventPipelineBehavior)
  • Event orchestration: Sequential and Concurrent execution strategies
  • Outbox pattern support with IEventOutboxStorage and PublishMode enum
  • Source generation with MediatorGenerator for automatic handler registration
  • Context propagation with IContext and IContextFactory
  • Integration with Result type for functional error handling

Active / Next (Short Horizon)

Item Status Notes
Outbox pattern improvements ⭐ Retry logic, dead-letter queue, batch processing
Request pipeline behaviors enhancement ⭐ Generic typed behaviors, conditional execution
Context enrichment πŸ“‹ Metadata helpers, correlation ID propagation
Handler result aggregation strategies πŸ“‹ Custom combiners for multi-handler event results
Notification vs Command clarification πŸ“‹ Explicit abstractions for one-way notifications

Event Publishing & Orchestration

Item Status Goal
Sequential orchestrator βœ… Execute handlers in order
Concurrent orchestrator βœ… Execute handlers in parallel
Custom orchestration strategies ⭐ Priority-based, conditional, throttled execution
Event filtering πŸ“‹ Handler selection based on runtime criteria
Event versioning πŸ“‹ Support multiple versions of same event type
Distributed event bus πŸ“‹ Integration with message brokers (RabbitMQ, Azure SB)
Event replay πŸ€” Reprocess events from outbox/event store

Request Handling Enhancements

Feature Status Purpose
Request/response with Result βœ… Functional error handling
Request without response βœ… Command pattern support
Streaming requests ⭐ IAsyncEnumerable support for large datasets
Request validation behavior ⭐ Built-in validation pipeline behavior
Request caching behavior πŸ“‹ Automatic response caching with invalidation
Request deduplication πŸ“‹ Prevent duplicate request processing
Request timeout behavior πŸ“‹ Automatic timeout enforcement
Multi-handler requests πŸ€” Support multiple handlers for single request (scatter)

Pipeline Behaviors

Feature Status Purpose
Request pipeline behaviors βœ… Cross-cutting concerns for requests
Event pipeline behaviors βœ… Cross-cutting concerns for events
Simple logging behavior βœ… Built-in logging example
Typed behaviors ⭐ Behaviors specific to request/event types
Conditional behavior execution ⭐ Execute behaviors based on context or metadata
Behavior ordering πŸ“‹ Explicit control over behavior execution order
Behavior composition πŸ“‹ Combine multiple behaviors into reusable pipelines
Performance monitoring behavior πŸ“‹ Track execution time and resource usage
Exception handling behavior πŸ“‹ Centralized exception mapping to Result errors

Outbox Pattern & Reliability

Feature Status Purpose
In-memory outbox storage βœ… Development and testing
Publish modes (Now/Outbox) βœ… Control event delivery timing
CommitAsync for batch send βœ… Process all pending events
Persistent outbox storage ⭐ EF Core, Dapper implementations
Outbox retry policies ⭐ Exponential backoff, max attempts
Dead-letter queue ⭐ Failed event handling
Outbox batch processing πŸ“‹ Process multiple events efficiently
Outbox cleanup πŸ“‹ Remove processed events after retention period
Outbox monitoring πŸ“‹ Track pending, failed, processed event counts
Idempotency support πŸ“‹ Prevent duplicate event processing

Source Generation & DI

Feature Status Purpose
RequestHandler attribute βœ… Mark classes for auto-registration
EventHandler attribute βœ… Mark classes for auto-registration
IRegisterGroup interface generation βœ… Type-safe DI registration
Handler discovery βœ… Automatic handler detection
Scoped vs singleton detection πŸ“‹ Infer or specify handler lifetimes
Multiple assemblies support πŸ“‹ Scan handlers across multiple projects
Conditional registration πŸ€” Register handlers based on build configuration

Performance & Scalability

Feature Status Purpose
ValueTask usage βœ… Reduce allocations for synchronous completions
Handler result caching πŸ“‹ Cache expensive request results
Request batching πŸ“‹ Group similar requests for efficiency
Streaming support ⭐ Handle large datasets with IAsyncEnumerable
Memory pooling πŸ“‹ Reuse buffers for event/request processing
Parallel event dispatching βœ… Concurrent orchestrator
Rate limiting behavior πŸ“‹ Throttle request/event processing
Backpressure handling πŸ€” Manage event queue overflow

Observability & Diagnostics

Feature Status Purpose
Context correlation ID βœ… Track requests across boundaries
OpenTelemetry integration ⭐ Distributed tracing and metrics
Request/event logging behavior βœ… Simple logging example included
Performance metrics πŸ“‹ Track handler execution time, success rates
Handler execution visualization πŸ“‹ Debug complex pipelines and behaviors
Diagnostic source integration πŸ“‹ .NET diagnostic infrastructure support
Health checks πŸ“‹ Monitor mediator and handler health
Debugger display attributes πŸ“‹ Rich debugging experience

Resilience & Error Recovery

Feature Status Purpose
Result-based error handling βœ… Functional error propagation
Retry behavior ⭐ Automatic retry with configurable policies
Circuit breaker behavior ⭐ Prevent cascading failures
Fallback behavior πŸ“‹ Provide default responses on failure
Timeout behavior πŸ“‹ Enforce maximum execution time
Bulkhead isolation πŸ“‹ Isolate handler failures
Compensating actions πŸ€” Saga pattern support for distributed transactions

Advanced Patterns

Feature Status Purpose
Request transformation πŸ“‹ Map one request type to another
Request aggregation πŸ“‹ Combine multiple requests into one
Event sourcing support πŸ€” Store events as source of truth
CQRS helpers πŸ“‹ Separate command and query infrastructures
Saga orchestration πŸ€” Long-running business processes
Request/event versioning πŸ“‹ Handle multiple versions of messages
Content-based routing πŸ€” Route to handlers based on message content

Testing & Developer Experience

Feature Status Purpose
In-memory testing utilities πŸ“‹ Test handlers without infrastructure
Mock mediator πŸ“‹ Test components using mediator
Behavior testing helpers πŸ“‹ Test pipeline behaviors in isolation
Request/event builders πŸ“‹ Fluent API for test data creation
Analyzer: missing handler ⭐ Warn when no handler registered
Analyzer: multiple handlers πŸ“‹ Warn about unexpected multiple registrations
Analyzer: async void handlers ⭐ Prevent common async mistakes
Code snippets πŸ“‹ VS/Rider snippets for common patterns
Migration guides πŸ“‹ From MediatR and other libraries

Integration & Interop

Feature Status Purpose
ASP.NET Core integration ⭐ Endpoint filters, minimal APIs
Native AOT compatibility βœ… Optimized for ahead-of-time compilation
Dependency injection support βœ… Microsoft.Extensions.DependencyInjection
Other DI containers πŸ“‹ Autofac, Simple Injector support
gRPC integration πŸ“‹ Use mediator in gRPC services
SignalR integration πŸ“‹ Publish events to connected clients
Azure Functions support πŸ“‹ Use mediator in serverless functions
Message broker adapters πŸ“‹ Publish events to external systems

Design Tenets

  • Result-based error handling for explicit success/failure
  • Native AOT compatibility for optimal performance
  • Source generation for zero-reflection handler registration
  • Pipeline behaviors for cross-cutting concerns
  • Flexible event orchestration strategies
  • Outbox pattern for reliable event delivery
  • Context propagation for correlation and tracing
  • Composability and extensibility at every level

Open Questions (Tracking)

  1. Should we support multiple handlers per request (scatter-gather pattern) or enforce single handler?
  2. What’s the best approach for handler lifetime management in source generation vs manual registration?
  3. Should pipeline behaviors have explicit ordering or rely on registration order?
  4. How deep should we integrate with observability frameworks (OpenTelemetry, Application Insights)?
  5. Should we provide built-in validation behavior or leave it to users/separate packages?
  6. Outbox pattern: should we support multiple storage backends out-of-the-box or provide interfaces only?
  7. How to handle versioning of events/requests in a breaking-change scenario?

Contributing

Issues / PRs welcome. When proposing a new feature, outline:

  • Category (Request Handling / Event Publishing / Pipeline / Orchestration / Integration)
  • Use case and benefits
  • Breaking changes or compatibility concerns
  • Performance implications
  • Integration with existing features
  • Testing strategy

Comparison with MediatR

UnambitiousFx.Mediator differentiates itself through:

  • Result-based APIs: First-class Result support for functional error handling
  • Native AOT: Optimized for ahead-of-time compilation with source generation
  • Event orchestration: Built-in concurrent and sequential strategies
  • Outbox pattern: First-class support for reliable event delivery
  • Modern C#: Leverages latest C# features (ValueTask, readonly structs, etc.)

Migration guide from MediatR: Coming soon πŸ“‹


Last updated: 2025-10-02