MideatR issue when combining with Hangfire

I’m using a popular MediatR package which works fine with IoC but combining with hangfire, my breakpoint does not get hit in my handler. I saw this post http://codeopinion.com/mediator-pattern-hangfire/ and I set the serialization settings but it still does not get hit.Can one usually debug the method that is being passed in? In my case --> _mediator.Send(loginRequest) which sends it to a handler. I use StyructureMap and the _mediator is set correctly as it works fine on non-hangfire code. The method below is called within my mvc controller action.

I have a method:
RecurringJob.AddOrUpdate(“informatica-job”, () => _mediator.Send(loginRequest), “*/15 * * * *”);

I also have:

public class LoginHandler : RequestHandler<JobWorkflow.LoginRequest>
private readonly IMediator _mediator;

public LoginHandler(IMediator mediator)
_mediator = mediator

protected override void HandleCore(LoginRequest loginRequest)
//**************** does not get hit at all**************

UPDATE: In fact I can’t debug any method passed in to recurring job. How does one debug the method passed in at all with hangfire?

Setup your hangfire server to use an Ioc container to create job classes. We use unity container and Hangfire.Unity nuget package to set it up, but there are several packages out there for your container of choice. Setup your hangfire server like this:

// create the container
IUnityContainer container = ConfigureMyContainer();
// assign it to hangfire
JobActivator.Current = new UnityJobActivator(container); // from Hangfire.Unity

I would just create a generic mediator job with dependency on mediator

public class MediatorJob {
    private IMediator _mediator;
    public MediatorJob(IMediator mediator) {
         _mediator = mediator;

    public void SendJob<T>(T command) {

Then schedule it like this

RecurringJob.AddOrUpdate<MediatorJob>("informatica-job", job => job.Send(loginRequest), "*/15 * * * *");

The way you had it setup originally, you don’t retain any context with the _mediator class, hangfire will recreate that class either with no-arg constructor or by using a container if you’ve configured it to do so, most likely you got an empty mediator object with no handlers setup.