1

Issue: most jobs are dependent on configuration dependency.

Ideal Solution: (copied here and at end just to save reading if you already know exactly how to do this)

I would like to

  • during job Q (using filter or any other options) save some data (object / json / string)
  • during job processing: intercept creation process of job and register dependency using stashed data to IoC container in scope for that job

Old Solution: for the custom "job scheduler" that I am replacing we take the following steps

  • before resolving the job processor we crate a lifetime scope and using job data register the dependency with data provided
  • then using "job type" resolve the job and process

Hack Solution: so this works for most but I still want to know how to accomplish what I am trying to do, by creating a "wrapper job" class that uses the same data to crate the same scope when running the job.

Ideal Solution: Ideally I can inject logic and

  • during save stash needed data (plenty of ways to do this)
  • during pre job processing access IoC to create the scope register this dependency

I have Tried / Looked Into Filter Attributes - works to save and restore data but have not found any access to IoC or lifetime scope here.

there were a few other options but they too were limited in "exposure" to the IoC container / scope

Ideal Solution: I would like to

  • during job Q (using filter or any other options) save some data (object / json / string)
  • during job processing: intercept creation process of job and register dependency using stashed data to IoC container in scope for that job
Steven
  • 166,672
  • 24
  • 332
  • 435
workabyte
  • 3,496
  • 2
  • 27
  • 35
  • You may give another chance to `Hangfire.Server.IServerFilter` For my part, I create an AsyncLocal scope object in `OnPerforming`, which I reset in `OnPerformed`. (My IoC is Ninject) – jbl Sep 01 '21 at 07:20
  • @jbl how are you getting a ref to the IoC container? Taking another look myself, thanks for the note! – workabyte Sep 01 '21 at 12:45
  • I don't need to directly access the IoC. It is automatically used to instantiate my composition root (the generic argument of the `Enqueue` method) – jbl Sep 01 '21 at 15:42

0 Answers0