github jbogard/MediatR v10.0.0
10.0.0

latest releases: v12.2.0, v12.1.1, v12.1.0...
2 years ago

This release adds support for IAsyncEnumerable<T>. A new request type, IStreamRequest<T> represents a request to create a stream, with a new handler type IStreamRequestHandler<TRequest, TResponse> to handle. An example:

public class StreamPing : IStreamRequest<Pong>
{
    public string? Message { get; init; }
}

public class PingStreamHandler : IStreamRequestHandler<StreamPing, Pong>
{
    public async IAsyncEnumerable<Pong> Handle(StreamPing request, 
        [EnumeratorCancellation] CancellationToken cancellationToken)
    {
        yield return await Task.Run(() => new Pong { Message = request.Message + " Pang" }, cancellationToken);
    }
}

Where the work inside of the handler would likely be calling some other streaming API, such as gRPC, EF Core streaming support, Dapper streaming etc.

There are also separate behaviors, with IStreamPipelineBehavior that are separate from the normal IPipelineBehavior.

With the addition of IAsyncEnumerable, this release now targets netstandard2.1 exclusively.

There are some breaking API changes, called out in the 10.0 migration guide.

Don't miss a new MediatR release

NewReleases is sending notifications on new releases.