Skip to content

Releases: jbogard/MediatR

4.1.0

20 Mar 20:58
99b77d8
Compare
Choose a tag to compare

This release adds explicit netstandard2.0 support, which should reduce dependencies for applications targeting netstandard2.0-based frameworks (netcoreapp2.0 etc.)

4.0.1

12 Dec 17:21
Compare
Choose a tag to compare

The last major release of MediatR brought a simplification in design. Instead of having several different IRequest types and IRequestHandler implementations with several flavors, MediatR would try at runtime to determine how a single IRequest should resolve to different IRequestHandler implementations (synchronous, async, async with a cancellation token). In practice, this proved problematic as not all containers support this sort of 'try-resolve' behavior. MediatR relied on try...catch to resolve, which can work, has unintended side effects.

MediatR 4.0 consolidates these design decisions. We'll still have a single IRequest type, but will now have only a single IRequestHandler interface. This simplifies the registrations quite a bit:

// Before (StructureMap)
cfg.Scan(scanner =>
{
    scanner.AssemblyContainingType<Ping>();
    scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
    scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler<,>));
    scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(ICancellableAsyncRequestHandler<,>));
    scanner.ConnectImplementationsToTypesClosing(typeof(ICancellableAsyncRequestHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(IAsyncNotificationHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(ICancellableAsyncNotificationHandler<>));
});

// After
cfg.Scan(scanner =>
{
    scanner.AssemblyContainingType<Ping>();
    scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
    scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<>));
    scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
});

This new default interface is the previous ICancellableAsyncRequestHandler interface:

public interface IRequestHandler<in TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}

public interface IRequestHandler<in TRequest>
    where TRequest : IRequest
{
    Task Handle(TRequest message, CancellationToken cancellationToken);
}

Instead of multiple interfaces, MediatR 4.0 (re)introduces helper base classes:

  • RequestHandler - for synchronous actions
  • AsyncRequestHandler - for async actions that ignore the cancellation token

With the simplified interfaces, it's much less possible to "forget" a registration in your container.

Another small but breaking change is the behavior pipeline and pre-processor now have the cancellation token as part of the interface.

Both the MediatR and MediatR.Extensions.Microsoft.DependencyInjection packages are released with the simplified API.

Since these are breaking changes to the API (hence the major version bump), migration to the new API is manual. However, to ease the transition, you can follow the 3.0 to 4.0 migration guide. I've also updated the docs to walk through the new classes, and the samples include the updated registrations for the major containers out there:

  • Microsoft DI
  • Autofac
  • DryIoc
  • LightInject
  • Ninject
  • Simple Injector
  • StructureMap
  • Unity
  • Windsor

A big move for MediatR to break the API, but necessary to remove the complexity in multiple interfaces and registration. The only other option would be to make MediatR responsible for all registration and wiring, which is more than I want MediatR to do. The design goal of MediatR is to lean on the power of DI containers for registration, and MediatR merely resolves its interfaces.

3.0.1

07 Mar 17:32
Compare
Choose a tag to compare

Fixes a bug around instantiating constructors multiple times

3.0.0

04 Jan 22:04
Compare
Choose a tag to compare

This release brings a major overhaul to the API of MediatR. The IMediator interface is now async-only, supporting optional cancellation tokens. The 'Async' postfix was not added onto the Send/Publish method names as there are no sync overloads.

On the handler side, you no longer need to build specific request/response types for sync/async. All request/notification types are IRequest or INotification. Instead, MediatR finds the appropriate handler implementation based on IRequestHandler, IAsyncRequestHandler and ICancellableAsyncRequestHandler.

The base class for RequestHandler is gone as well, with just the interfaces remaining.

New in this release are built-in support for pipelines through behaviors, which you can find more information about in the wiki.

2.0

04 Aug 18:18
Compare
Choose a tag to compare
2.0

Removes all dependencies, adds support for cancellation tokens, and supports All The Platforms