I have a asp.net application that uses
builder.Services.AddControllers()
.AddNewtonsoftJson();
This causes the return of the controller not to run asynchronous
[HttpGet("IAsyncTest")]
public IAsyncEnumerable<TestDTO> GetTestValue()
{
return _getValues();
}
private static readonly TestDTO[] _values = new[]
{
new TestDTO {IntValue= 1, StringValue = "Value 1"},
new TestDTO {IntValue= 2, StringValue = "Value 2"},
new TestDTO {IntValue= 3, StringValue = "Value 3"},
new TestDTO {IntValue= 4, StringValue = "Value 4"},
new TestDTO {IntValue= 5, StringValue = "Value 5"},
};
private async IAsyncEnumerable<TestDTO> _getValues()
{
foreach (var value in _values)
{
yield return value;
await Task.Delay(TimeSpan.FromSeconds(20));
}
}
Is there a way to use Newtonsoft only in certain controllers not all of them? Or specify which controller uses Text.Json.
Or Is it possible to create a custom formatter that uses that Text.Json for IAsyncEnumerable.
Code example is here: GitHub Link
Thanks for helping