Asynchronous actions

ASP.NET Core supports asynchronous actions that are implemented with the async-await pattern. If the method action return type is Task or Task<T>, ASP.NET Core will await the Task, and once completed, the result will be sent back to the client.

For example, here is an asynchronous version of the AddNewProduct action that adds a short delay (for demonstration purposes) and awaits it:

[HttpPost("")]
public async Task<ActionResult<NewProductDTO>> AddNewProduct([FromBody] NewProductDTO newProduct)
{
await Task.Delay(1000);
if (!ModelState.IsValid)
{
return new BadRequestResult();//(ModelState);
}
return new ObjectResult(newProduct);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.71.211