DRY principles needed in .NET Core WebAPI. I want to avoid using repetitive try/catch blocks, repetitve logging commands, and account for HTTP response codes such as 404, 200, 204, etc and minimize API method lines of code into some interface or service. Goal would be to have no IF statements and one line of code in the API.
Lot's of homework...
[HttpGet()]
[Route("Contracts/{id}")]
public async Task<IActionResult> Get(int id)
{
var results = await _service.GetContractByIdAsync(id);
// TODO: Need a better way to do this
// TODO: Logging, but imlpemented cleanly
// Error handling, but don't want a bunch of try/catch block copied and pasted
if (results == null) { return NotFound(); }
return Ok(results);
}
Aucun commentaire:
Enregistrer un commentaire