MediatR 5.0 Released
Another milestone for MediatR, I released 5.0 over the weekend. This release simplifies a number of interfaces and methods, but introduced some breaking changes along the way.
The major change for MediatR in 5.0 is the combination of void requests to directly implement IRequest<Unit>
. In 4.x:
public interface IRequest<T> : IBaseRequest { }
public interface IRequest : IBaseRequest { }
And in 5.0:
public interface IRequest<T> : IBaseRequest { }
public interface IRequest : IRequest<Unit> { }
For the handlers, in 4.x:
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 request, CancellationToken cancellationToken);
}
And in 5.0:
public interface IRequestHandler<in TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}
public interface IRequestHandler<in TRequest> : IRequestHandler<TRequest, Unit>
where TRequest : IRequest<Unit>
{
}
While the original 4.x interfaces were convenient for void-based requests, having a completely separate interface meant that you really couldn't use pipeline behaviors or pre/post processors. With the 5.0 merging of interfaces, you can use the full feature set of MediatR without worrying about weird container problems.
I've kept the helper base classes if you need them, and written up some release notes and migration guide.
With this release, I don't see any more changes in the interfaces for IMediator
, the requests, or handlers.
Enjoy!