Created
July 15, 2019 08:16
-
-
Save ducmeit1/7147725783a32db9fb946368b2380c61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using MediatR; | |
using Microsoft.AspNetCore.Mvc; | |
namespace Customer.API.Controllers | |
{ | |
[ApiController] | |
[Route("api/[controller]")] | |
[Produces("application/json")] | |
public class ApiControllerBase : ControllerBase | |
{ | |
private readonly IMediator _mediator; | |
public ApiControllerBase(IMediator mediator) | |
{ | |
_mediator = mediator ?? throw new ArgumentNullException(); | |
} | |
protected async Task<TResult> QueryAsync<TResult>(IRequest<TResult> query) | |
{ | |
return await _mediator.Send(query); | |
} | |
protected ActionResult<T> Single<T>(T data) | |
{ | |
if (data == null) return NotFound(); | |
return Ok(data); | |
} | |
protected async Task<TResult> CommandAsync<TResult>(IRequest<TResult> command) | |
{ | |
return await _mediator.Send(command); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment