ardalis / ApiEndpoints

A project for supporting API Endpoints in ASP.NET Core web applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for IAsyncEnumerable

DorianGreen opened this issue · comments

Right now, in order to return an IAsyncEnumerable you need to use EndpointBaseSync and access the request cancellationToken form HttpContext like this:

public class List : EndpointBaseSync.WithoutRequest.WithResult<IAsyncEnumerable<PropertyListResult>>
{
    /// <summary>
    /// List all Properties
    /// </summary>
    [HttpGet("api/[namespace]")]
    public override async IAsyncEnumerable<PropertyListResult> Handle()
    {
        var cancellationToken = HttpContext.RequestAborted;
        await Task.CompletedTask;
        yield break;
    }
}

It would be nice if we could do something like this:

public class List : EndpointBaseAsync.WithoutRequest.WithAsyncEnumerableResult<PropertyListResult>
{
    /// <summary>
    /// List all Properties
    /// </summary>
    [HttpGet("api/[namespace]")]
    public override async IAsyncEnumerable<PropertyListResult> Handle(CancellationToken cancellationToken = default)
    {
        await Task.CompletedTask;
        yield break;
    }
}

See also jbogard/MediatR#574 (comment) as a reference for the needed targetframework changes.

#176 is waiting for merge.
targetframework has been bumped to netcore3.1 with #180 and so no need to change targets anymore

Feature is now in main.
Issue can be closed <3

is the only thing missing, a new nuget version?

I guess it has been a while...

are you sure? 4.0.1 does not include WithAsyncEnumerableResult
image