Created
June 10, 2016 01:37
-
-
Save dcomartin/874661c6a51dbb80c90121d81233f637 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 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);
}
}
}