You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bartelink edited this page Mar 21, 2013
·
9 revisions
This is basically the same as InTransientScope() insofar as it comes to the lifecycle and the decision of which object is injected. As with InTransientScope, a new instance is injected for each dependency. The difference to InTransientScope is that instances emanating from bindings with this scope will be deactivated after the object that gets the instance injected is deactivated.
public class Foo
{
public Foo(Bar bar) { ... }
}
public class Bar : IDisposable { ... }
Bind<Bar>().ToSelf().InParentScope();
In other words when the parenting object is collected by the garbage collector (or preemptively released by a lifetime management system such as Ninject.Web.Mvc which Kernel.Releases at the End of a Request), the container automatically Disposes the object as part of the same cleanup work.
In this example Bar gets Disposed by Ninject as soon as Foo gets collected by the garbage collector [or actively released e.g. by per-call Releasing of a scoping object].