-
Notifications
You must be signed in to change notification settings - Fork 6
InParentScope
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.Release
s at the End of a Request), the container automatically Dispose
s the object as part of the same cleanup work.
In this example, the Bar instance gets Dispose
d by Ninject as soon as the parent Foo
instance gets collected by the garbage collector (or actively released e.g. by per-call Releasing of a scoping object).
- Home
- Sibling applied mechanism: InCallScope
- General mechanism: InNamedScope
- Architectural discussion: Child Kernel versus Named Scope
- Low level programmatic mechanism: CreateNamedScope/GetScope