Should I use Dependency Injection with scheduled jobs?

I see a lot of questions on how to set up Hangifre with some DI framework. I work on a web application where we use Ninject but I am curios why would I even bother? I f i have a job running every night cant I just new up the db context (EF) and pass is as a parameter for my method? Then i can still test my method without running the job. Would´nt it actually be better to run in its own context?

With DI you’ll still get your own context (depending upon how it is configured). It looks like your question is what is the benefit of DI regardless of Hangfire. There are tons of article online that answers this question.

1 Like