Monday, January 29, 2018

New pattern coming to MVC Core 2.1, ActionResult returns

From David Fowler's own mouth:

It's a discriminated union that solves the, I want to return an object or a 404 without needing to throw an exception.

TL;DR on example:

 [HttpGet] public ActionResult<Product> GetProduct(int? productId) { if (productId == null) { return BadRequest(); } return new Product { SampleInt = productId.Value, }; } 
New pattern coming to MVC Core 2.1, ActionResult<T> returns Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team