Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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