Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Last active March 29, 2018 23:32
Show Gist options
  • Select an option

  • Save wellingtonjhn/3686dc5c03b2eefc97a2b30129de3f80 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/3686dc5c03b2eefc97a2b30129de3f80 to your computer and use it in GitHub Desktop.
ASP.Net Controllers with MediatR
[Route("api/[controller]")]
public class AccountsController : Controller
{
private readonly IMediator _mediator;
public AccountsController(IMediator mediator)
{
_mediator = mediator;
}
[HttpPost, AllowAnonymous, Route("login")]
public async Task<IActionResult> Authenticate([FromBody] AuthenticateUser command)
{
var response = await _mediator.Send(command);
if (response.Errors.Any())
{
return BadRequest(response.Errors);
}
return Ok(response.Value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment