Which scope must be used if we want the instance collected by the GC to be disposed properly?

StackOverflow https://stackoverflow.com/questions/15465323

  •  24-03-2022
  •  | 
  •  

Question

Must InParentScope be used if one wants an instance collected by GC to be Disposed properly ? If not which Scope should be used instead?

Was it helpful?

Solution

If your question is not covered by https://github.com/ninject/ninject/wiki/Object-Scopes, I'll be happy to make any changes needed based on any follow-ups you have.

OTHER TIPS

Objects any scope except InTransientScope() are disposed when the lifetime of the scope ends. There is no correct one as the scope defines how long an object lives and this depends on the concrete situation.

An object InParentScope() is Disposed when the object it is injected into is either garbage collected or when it is deactivated by Ninject because its own scope has ended.

Note that if the Scope of the Parent is InTransientScope(), the object will not be tracked, so use it with care.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top