Skip to content

Upgrading MediatR 11 to 12

Breaking11.1.0 → 12.5.0Breaking7New8Changed7Fixed6Other14

BreakingUpgrade verdict

7 breaking changes.

  • Removes extraneous interfaces and classes for exceptions.
  • You can no longer rely on automatic discovery of behaviors and processors. You must register each one yourself, which also lets you control their order.
  • Generic handlers are no longer registered automatically; you must explicitly enable that behavior.
  • Consolidates registration into a single configuration object and optimizes registration.
Top 3 of 7 that need code or config changes

MediatR publishes an official migration guide for version 12. It covers more than the release notes do.

Migration Guide ↗

Target frameworks requirement changed in 12.0.1: .NETStandard2.1 → .NETStandard2.0, net6.0.

Adds microsoft.bcl.asyncinterfaces 8.0.0, microsoft.extensions.dependencyinjection.abstractions 8.0.0.

Moves mediatr.contracts 1.0.1 → [2.0.1, 3.0.0). Your build may pick other versions.

Breaking7
Removes extraneous interfaces and classes for exceptions.
Requires explicit registration of behaviors, stream behaviors, and pre/post processors inside AddMediatR; scanning is removed.
AddMediatR
Makes auto registration of generic handlers opt-in instead of automatic.
Consolidates registration into a single configuration object and optimizes registration.
Changes the type constraint of pipeline behavior to allow easier chaining.
IPipelineBehavior
Scales back generic constraints.
Changes IRequest to return a normal Task instead of Task<Unit>.
IRequestTaskTask<Unit>