Hangfire Filters and IoC with Ninject

Hi there

I’m using Hangfire with Ninject, and I’d like to make use of the Filters to add a generic job tracking Attribute that allows me to access the job id and its performed state.

However, I want this attribute/filter to have access to a service object injected by Ninject. If I add a constructor to my JobFilterAttribute with the service as a parameter I, understandably, get the does not contain a constructor that takes 0 arguments error.

MVC/Ninject takes the following approach to solve this (splitting the Attribute and Filter and then Binding them in the Ninject configuration) and I wondered if there was a similar approach for Hangfire: http://stackoverflow.com/a/6205526
__

Alternatively, is there a way of accessing the currently running Job’s job id from within the method itself? Ninject will happily inject my service when the instance is activated, but I can’t see an obvious way of finding the job id at that point.

Many thanks for your suggestions!

1 Like