Skip to content
remogloor edited this page Feb 12, 2011 · 9 revisions

This is basically the same as InTransientScope() at least when it comes to the lifecycle and the decision which object is injected. As with InTransientScope a new instance is injected for each dependency. The difference to InTransientScope is that bindings with this scope will be deactivated after the object that gets the instance injected is collected by the garbage collector. E.g. the container disposes the object when it is not used anymore.

public class Foo
{
    public Foo(Bar bar) { ... }
}
 
public class Bar : IDisposable { ... }
 
Bind<Bar>().ToSelf().InParentScope();

In this example Bar gets disposed by Ninject as soon as Foo gets collected by the garbage collector.

Clone this wiki locally