Repository navigation
v7.1.1
This release fixes dispatch to generic handlers of generic messages, which broke in 7.0.0 (#169), and five more mediation defects in the same area. Open generic guards and pre-handlers never ran for generic messages, so a guard meant to deny every command let generic commands through. A message definition registered after a handler could leave a message with no handlers. A message whose own type was never registered skipped the handlers of all but one of its base types and interfaces. TrySendAsync and TryQueryAsync reported success for a refusal that escaped a handler. One event handler's timeout stopped the rest of its group under ContinueAndAggregate. Upgrade if you use generic messages, open generic pipeline handlers, message definitions, base-type or interface handlers, the Try methods, or ContinueAndAggregate. No application code or configuration changes. One main-handler resolution rule changed, described under Changed.
Added
- The
Consumer SmokeCI job also sends generic messages through the mediator from the packed packages, in the shapes from #169: a query whose result nests the type parameter, a command with two type parameters, an open generic pre-handler and a typed post-handler on that command, a stream query, and a handler for a generic event interface. This scenario needs no database. Run against the 7.1.0 packages, it fails with theInvalidCastExceptionfrom #169. See Consumer Smoke Test.
Changed
- When a command or query has no handler registered for its own type, and handlers are registered for several of its base types or interfaces, the handler registered for the most-derived type runs. Handlers for equally derived types throw
AmbiguousMessageResolveException. This applied before only to a message that was never registered. A message registered at startup, which is what assembly scanning does, threwMultipleHandlerFoundExceptioninstead, so the same message reached a handler or threw depending on how it was registered. A handler for a closed generic message's own generic definition, such asListQueryHandler<T>forListQuery<string>, still wins over every base-type handler, and a handler registered for the closed message still overrides it. See Message Descriptor Resolution Precedence. - Each module now also registers every open generic handler definition, such as
Guard<>, with the dependency injection container, next to its closures. A closure created after the container was built resolves from it.
Fixed
- Generic handlers of generic messages are dispatched again when the handler's contract nests a type parameter or the message has more than one (#169). Versions 7.0.0 and 7.1.0 closed the handler and its contract by passing the message's type arguments in order, which fits only a contract whose result is
Task<T>withTas the message's only type argument.ListQueryHandler<T>forListQuery<T> : IQuery<List<T>>failed withInvalidCastException, andCreateEntityCommandHandler<TEntity, TKey>forCreateEntityCommand<TEntity, TKey> : ICommand<TKey>, the example in the generic messages guide, failed withArgumentException. The same mismatch broke stream query handlers, and typed post-handlers and completion handlers whose result is not the message's first type argument. Any handler, including pre-handlers and error handlers, also failed when it declared its type parameters in another order than the message or nested one inside a message type argument. The mediator now binds each type parameter by matching the message type the handler names against the runtime message, so all of these shapes reach their handlers. - A generic handler for a generic interface, such as
EntityChangedHandler<TEntity> : IEventHandler<IEntityChanged<TEntity>>, now handles a non-generic message that implements the interface. It failed withArgumentException, because the message has no type arguments of its own. - When two generic handlers of one generic message differ in their constraints, such as
where T : classandwhere T : struct, or in the shape of the message's type argument, such asEnvelopeQuery<List<T>>andEnvelopeQuery<T[]>, each message now reaches the handler that fits it, as the generic messages guide describes. Every message failed withMultipleHandlerFoundException. A handler that fits no shape of a message, or whose constraints reject it, is now left out of that message's pipeline instead of failing to resolve. - A generic handler whose type parameter does not appear in the message type it handles, and a message that implements the handled generic interface twice with different type arguments, now fail at dispatch with a
PipelineContractExceptionthat names the handler and the type parameter or interface. They failed with aMemberAccessExceptionorArgumentExceptionfrom reflection. - An open generic handler over a bare type parameter, such as an authorization guard
Guard<T> : ICommandGuard<T>or aLoggingPreHandler<T> : ICommandPreHandler<T>, now runs for generic messages such asCreateEntityCommand<Product>. It never ran for them, because the registry closed such handlers only over registered closed messages, and a generic message is registered by its open definition. A guard meant to deny every command let every generic command through without an error. A closed generic message is now registered on its first dispatch, which closes every applicable open generic handler over it. 6.0.2 behaves the same. - When a message definition, such as an idempotency, audit, or authorization definition, was registered after the handler for a message that had no registration of its own, sending that message threw
NoHandlerFoundException. This hit a definition for a closed generic command, such asIIdempotencyDefinition<ArchiveCommand<string>>, which is the only way to declare metadata for a generic message, and a definition for a derived command handled by its base class. With assembly scanning the outcome depended on the order of types in the assembly. A definition now links the message it registers to every handler registered before it. - A message whose own type was never registered used the handlers of one registered base type or interface and skipped the others. A command whose base class has a handler skipped the pre-handler on an interface it implements, with no error, and an event that implements two handled interfaces threw
AmbiguousMessageResolveExceptioninstead of running both handlers. This affects messages that are never registered: when an application registers only handlers, for struct messages, which assembly scanning does not register, and for messages from assemblies that are not scanned. Such a message is now registered on its first dispatch, which links the handlers of every base type and interface it has. 6.0.2 behaves the same. - When a refusal reached
TrySendAsyncorTryQueryAsyncfrom inside the handler, because the handler sent a command its guard denied or threwLiteBusMessageDeniedExceptionorLiteBusMessageInvalidExceptionitself, the result reportedSucceededwith a default value. It now reportsDeniedorInvalidwith the reason, code, and failures the exception carries, and no value.MediationHarnessinLiteBus.Testing.Mediationreports it the same way. - With sequential handlers under
HandlerFaultMode.ContinueAndAggregate, anOperationCanceledExceptiona handler raised itself, such as anHttpClienttimeout, stopped the rest of its priority group, so the subscribers after it never ran. It is now collected like any other failure. Cancelling the token passed toPublishAsyncstill stops the group.
Documentation
- The generic messages guide gains How LiteBus Closes a Generic Handler, which describes how type parameters are bound, which handler shapes it covers, and the two errors it reports.
- Handler Resolution Internals gains Messages Registered at Dispatch and the order in which a command or query chooses its main handler. Polymorphic Dispatch describes the same rules from the application's side.
- The handler pipeline page says how a
Trymethod reports a refusal that escapes a handler, and the events page says which cancellations stop a sequential group.