I have a controller with one action. In this action method, I have an async
method that I call and that is it. This is the code that I am using:
[HttpGet]
public Task<MyObject> Get()
{
return _task.GetMyObject()
}
This serializes correctly into the JSON I expect from it. Now my manager insists that the signature should be changed to the following:
[HttpGet]
public async Task<IActionResult> Get()
{
var data = await _task.GetMyObject();
return Ok(data);
}
I'm of the belief that there is no reason for the code to await
in the controller and can just return the Task
because nothing afterwards depends on the result. Apart from the extra code generation (creation of state machine etc.) done for the await
, are there any implications from a WebApi
point of view of these approaches? To clarify, I want to know if returning an IActionResult
is better than to just return Task<MyObject>
even tho it seems like the results are the same.