Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created September 30, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/74cca52c5bdb484e72017069dbc0a48d to your computer and use it in GitHub Desktop.
Save dcomartin/74cca52c5bdb484e72017069dbc0a48d to your computer and use it in GitHub Desktop.
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