Yes, I would recommend using InThreadScope . When a pool thread stream is used, a leak will occur.
In addition, there is nothing built into ninject like "QuartzScope", so you will need to create your own solution. start by creating a job. This fooobar.com/questions/966938 / ... and, in more detail, the source code for this nuget package .
Now, one of the possible solutions is the JobFactory extension for controlling the creation of the DbContext and its entry into the task and all its dependencies (as an inherited parameter of ConstructorArgument ). However, this has two drawbacks: it always creates a DbContext (whether this task is needed or not), and you need to track DbContext instances DbContext that you can .Dispose() of them in the IJobFactory.ReturnJob(IJob) (p.ex. a Dictionary<IJob, DBContext or the like).
It is much easier to use .InCallScope (included in Ninject.Extensions.NamedScope ) to bind DbContext . This will create one instance of DbContext per kernel.Get<FooJob>() .
If you need different uses for DbContext - depending on where you use them, p.Ex. inside the job and inside your ASP.NET MVC stuff, can you watch the Ninject Conditional Self bind to change the scope (for Task-scheduler) not working properly?
source share