ardalis / ApiEndpoints

A project for supporting API Endpoints in ASP.NET Core web applications.
MIT License
3.13k stars 227 forks source link

Add support for IAsyncEnumerable #175

Closed DorianGreen closed 1 year ago

DorianGreen commented 2 years ago

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;
    }
}
cmxl commented 2 years ago

See also https://github.com/jbogard/MediatR/pull/574#issue-736342983 as a reference for the needed targetframework changes.

cmxl commented 2 years ago

176 is waiting for merge.

targetframework has been bumped to netcore3.1 with #180 and so no need to change targets anymore

cmxl commented 1 year ago

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

AlexanderFinkbeiner commented 1 year ago

is the only thing missing, a new nuget version?

ardalis commented 1 year ago

I guess it has been a while...

AlexanderFinkbeiner commented 1 year ago

are you sure? 4.0.1 does not include WithAsyncEnumerableResult image