Exactly how long is "InSingletonScope" for webapp?

I just wash my feet with the Ninject.Mvc3 NuGet package, and I wonder how long the created object lasts.

InRequestScope pretty clear: every object created in this area lives as long as the web server processes a specific web request. (To be pedantic, objects live as long as the HttpContext.Current object does)

But how long does the InSingletonScope ? The documentation states that as long as the Ninject kernel itself does this, which completes the static NinjectWebCommon class. The best guess I have made so far is that the kernel lives as long as the webapp is running on the server - until the server is working, until the application is manually reloaded in IIS or updated, objects are in scope .

I am curious because I am tempted to have some Data Accessors containing read-only data dictionaries like Singleton Scope, and I am wondering if this is a good idea or memory leak when planning.

+4
source share
2 answers

This will continue until your ASP.NET application pool lasts.

When will your application pool be processed? There are many settings that govern this: read Configuring Application Pool Reinstall Settings (IIS 7) .

Basically, it won’t last forever: if you want to store read-only data, just make sure you load everything in Application_Start() so that it is ready when the requests are in and you have to go well.

+4
source

You're right. While the application pool is running, your singlets will live. Why you can disable reloading the application pool.

On most of my websites, I configure caching in static classes (or as single elements using Ninject or StructureMap) and data in dictionary safe dictionaries. This, of course, consumes memory, but it is not a memory leak. Work in accordance with the project.

+2
source

All Articles