We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Job Activation scope and Job Filters

Would be nice if the Job’s Activation Scope (say an Autofac lifetime scope) is available for use from within the PerformContext, so that my Job Filter Attributes can interface with the job’s lifetime scope.

Reason I need this is to invisibly transfer over some application context from the calling side to the job side, if a Hangfire job is marked with a certain attribute.

So far I was able to do this by creating an entry within JobParameters and fetching it using IClientFilter and IServerFilter. Last piece of this puzzle is to initialize a lifetime-scoped object in the job’s context with this value, but looks like the scope is created after the filters run (inside CoreBackgroundPerformer).

I can still accomplish this using a ThreadLocal (or AsyncLocal) value, but that’s less than ideal. I feel like BackgroundJobPerformer and CoreBackgroundJobPerformer can be merged.

Another way to solve this would be to make PerformContext available for injection within the Job’s scope, so that I can transfer the value into the Items property inside the filter, and then initialize my lifetime-scoped objects by directly injecting in PerformContext.

Thoughts? Any other smart way of doing this?