Stilgar
Stilgar

Reputation: 23561

Can't get Ninject to dispose object in Request Scope

I can't seem to get Ninject to dispose objects in request scope in an ASP.NET MVC application with web API no matter what I do.

What I am doing:

I have read a bunch of questions including this one - Ninject doesn't call Dispose on objects when out of scope and the Ninject documentation https://github.com/ninject/Ninject.Web.Common/wiki/InRequestScope and they both indicate that due to the fact that Ninject.Web.Common includes a registration for the OnePerRequestHttpModule (yes it is there) the disposal should just work but it doesn't. I also tried adding the PerRequest module in the web.config and got an error saying that I can't have this section in integrated mode.

At this point I am lost. I suspect either integrated mode or OWIN have something to do with this but I have no idea how to debug it or what to do to fix it. Any suggestions?

Upvotes: 4

Views: 2489

Answers (1)

Frank
Frank

Reputation: 4481

The object not being disposed was a problem in Ninject.Web.Common before version 3.2.2, as discussed here: InRequestScope is failing to dispose objects

As you have been installing Ninject via nuget, you probably installed the oldest supported dependencies. This can be avoided by using:

Install-Packages Ninject.MVC5 -DependencyVersion Highest

Please verify that you are using the current version of all Ninject packages.

Upvotes: 7

Related Questions