What's New
IMediatorBuilder Fluent API
AddMediator() now returns IMediatorBuilder instead of IServiceCollection, enabling fluent chaining for extension packages:
services.AddMediator().AddQueues();CallContext & HTTP Binding
CallContext— A new pooled, lightweight mechanism for passing request-scoped objects (HttpContext,HttpRequest,HttpResponse) to handler and middleware methods, reducing allocations and improving testability- HTTP binding attributes — Message properties can now use
[FromHeader],[FromQuery], and[FromRoute]to bind values from the HTTP request before the handler is invoked
Handler Metadata & Registry
HandlerRegistrynow stores rich attribute metadata, source type/method names, parameter types, and stableDescriptorIdidentifiers- New indexed lookups by attribute type and descriptor ID for extension packages and middleware
HandlerExecutionInfoincludes an optionalDescriptorIdfor improved traceability
MessageContext<T> Subscriptions
mediator.SubscribeAsync<MessageContext<T>>() wraps subscription messages with publisher metadata (ActivityContext), enabling trace context propagation across publish/subscribe boundaries.
Result Type Improvements
Result.Accepted(message, location)— New overload that accepts a location string (e.g., a job status URL). Generated endpoints now emit a proper HTTPLocationheader on 202 responses.Result.FromResult(IResult)— Safe cross-type conversion betweenResultandResult<T>, replacing hard casts in generated middleware pipelines
Endpoint Generation Enhancements
- Improved route generation with better handling of non-CRUD verbs and kebab-case conversion
- Refactored to use
Groupterminology (replacingCategory) for clarity and consistency - New
RouteConventionsutility encapsulating shared routing logic ClaimsPrincipalis now automatically available as a handler parameter in endpoints- Assembly name included in endpoint mapping log messages for modular apps
Authorization & OpenTelemetry
- Generated handlers skip redundant authorization for event/notification dispatch (
skipAuthorizationparameter) - Notification handler activities now include the handler class name (e.g.,
Handle OrderHandler.OrderCreated) IAuthorizationContextProviderfalls back toThread.CurrentPrincipalwhenHttpContextis unavailable (background workers)
Infrastructure
- Startup logging moved from
Console.WriteLinetoILoggerFactory-backed logging - Enabled
TreatWarningsAsErrorsand fixed all nullable reference type annotations - New endpoint benchmarks comparing hand-coded minimal APIs vs source-generated endpoints
- Updated to .NET 10.0.5 dependencies
Bug Fixes
- [HandlerEndpoint] override — An explicit
[HandlerEndpoint]attribute now correctly overrides the event handler auto-exclude heuristic. Previously, handlers with class names ending inEventHandlerwere excluded from endpoint generation even when explicitly annotated. (#150) - Safe Result conversion — Generated middleware pipelines now safely convert between
Resulttypes instead of throwingInvalidCastExceptionwhen the middleware returns a differentIResulttype than the handler declares
Contributors
Thanks to all contributors and the Dependabot for keeping dependencies up to date!
Full Changelog: v1.0.1...v1.1.0