This is a common life time management problem. The basic rule is that whoever creates the object has the right to own this instance. The owner must dispose of / destroy this instance. Property can be transferred to someone else, which makes βsomeone elseβ responsible for the destruction of this instance.
In your case, the Foo instance is not created by Bar, so bar is not responsible for deleting this instance. Since Ninject created this instance for you, it is responsible for cleaning it up.
Property can be transferred, but it must be something explicit. A good example of explicit ownership transfer is the Factory design pattern:
IFoo CreateNewFoo();
Although this method creates new instances of IFoo , it is pretty clear that it transfers ownership back to the caller.
A good example of a BAD method of transferring ownership is the .NET StreamReader class. It takes a one-time object in its constructor, but it takes responsibility. Although the documentation states that the class has this object, this behavior blinds many developers because it contradicts the general rule of ownership. Microsoft finally fixed this in .NET 4.5 by adding ctor overload, which can suppress deletion of a given stream.
source share