Injecting EF Context per-thread get a new instance per job?

I’m injecting my EF context using Ninject using an ‘InThreadScope’. This works fabulously except for if an exception occurs on the context. This makes the context stale and causes ALL subsequent jobs on the same worker # to also fail (As they run in the same thread).

Is there a recommended way to handle such a situation? Or is it best to just dispose my context at the end of each job to force Ninject to spawn a new one?

Alternatively if there is a way to force each worker to run in a fresh thread for each job. This would resolve this (and any other thread specific issues) in the future.

I would spawn a new context for each job since reusing the same context over a long period of time can cause all kinds of issues.

We had to create a UnitOfWorkScope that disposed after the job completed.

Here is a repository with a sample.

We also use the UnitOfWorkScope through a controller request on our website. It is similar to InRequestScope for Ninject.