-
-
Save dcomartin/74cca52c5bdb484e72017069dbc0a48d to your computer and use it in GitHub Desktop.
This file contains 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; | |
using System.Threading.Tasks; | |
using Hangfire.MediatR; | |
using MediatR; | |
using Microsoft.AspNetCore.Mvc; | |
namespace Sales | |
{ | |
public class PlaceOrder : IRequest | |
{ | |
public Guid OrderId { get; set; } | |
} | |
public class PlaceOrderController : Controller | |
{ | |
private readonly IMediator _mediator; | |
public PlaceOrderController(IMediator mediator) | |
{ | |
_mediator = mediator; | |
} | |
[HttpPost("/sales/orders/{orderId:Guid}")] | |
public IActionResult Action([FromRoute] Guid orderId) | |
{ | |
_mediator.Enqueue("Place Order", new PlaceOrder | |
{ | |
OrderId = orderId | |
}); | |
return NoContent(); | |
} | |
} | |
public class PlaceOrderHandler : IRequestHandler<PlaceOrder> | |
{ | |
public Task<Unit> Handle(PlaceOrder request, CancellationToken cancellationToken) | |
{ | |
// Do your actual work here | |
throw new NotImplementedException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment