Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created June 10, 2016 01:37
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/874661c6a51dbb80c90121d81233f637 to your computer and use it in GitHub Desktop.
Save dcomartin/874661c6a51dbb80c90121d81233f637 to your computer and use it in GitHub Desktop.
using Hangfire;
namespace MediatR
{
public static class MediatRExtension
{
public static void Enqueue(this IMediator mediator, IRequest request)
{
BackgroundJob.Enqueue<HangfireMediator>(m => m.SendCommand(request));
}
}
public class HangfireMediator
{
private readonly IMediator _mediator;
public HangfireMediator(IMediator mediator)
{
_mediator = mediator;
}
public void SendCommand(IRequest request)
{
_mediator.Send(request);
}
}
}
@deaquino
Copy link

deaquino commented Jan 11, 2019

Hi!

I suggest to change to awaitable tasks and add a new method for Generic requests.

using MediatR;
using System.Threading.Tasks;
namespace WMS.Domain.Model.Hangfire
{
public class HangfireMediator
{
private readonly IMediator _mediator;
public HangfireMediator(IMediator mediator)
{
_mediator = mediator;
}
public async Task Send(IRequest request)
{
await _mediator.Send(request);
}
public async Task Send(IRequest request)
{
await _mediator.Send(request);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment