Fix closing order
This release fixes two bugs :
- The objects were closed in a random order. It was possible to have an object with a closed dependency. The objects are now closed in the right order. The dependencies are closed after the objects using them.
- The second bug was created in the last release. The Close function could be called on an object that was being built. In this case it was not possible to cast the object given to the Close function.