Skip to content

2.1.0

Choose a tag to compare

@Adiakys Adiakys released this 01 Nov 11:28
· 24 commits to main since this release
255523c

MediatR compatibility

AnyMediator 2.1 closes the remaining gaps with MediatR: behaviors, handlers and calls written for MediatR now work unchanged once the namespace and AddMediatR are replaced.

Changes from 2.0.0 that need attention

2.0.0 was published the day before this release and had no downloads, so these changes ship as a minor version.

  • Publish re-throws failures, as MediatR does. Every sink still runs; one failure is re-thrown as is, several as an AggregateException. In 2.0.0 failures were logged and swallowed. The dependency on Microsoft.Extensions.Logging.Abstractions is removed.
  • Two handlers for the same request make AddAnyMediator throw, naming both classes. In 2.0.0 the first one found was used silently.
  • ISender.Send(object) and IPublisher.Publish(object) are new interface members: classes that implement ISender or IPublisher by hand must add them. Mocks are unaffected.

New

  • Handlers for a notification's base class or interface also receive it: INotificationHandler<IDomainEvent> runs for every IDomainEvent. A handler class runs once per Publish.
  • Open generic handlers are found by scanning and closed when a message is dispatched, e.g. GetByIdHandler<T> : IRequestHandler<GetById<T>, T> or IndexEntity<T> : INotificationHandler<EntityCreated<T>>.
  • IPipelineBehavior and IStreamPipelineBehavior constrain TRequest to notnull, so MediatR behaviors compile unchanged.
  • Send(object), CreateStream(object) and Publish(object) for messages whose type is only known at runtime; Publish(object) passes the runtime type to sinks.
  • cfg.TypeEvaluator filters the types registered by scanning.

Docs: Upgrading from AnyMediator 2.0

What's Changed

  • 2.1.0: MediatR-compatible Publish errors, object overloads, generic and polymorphic handlers by @Adiakys in #16

Full Changelog: 2.0.0...2.1.0