boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.13k stars 136 forks source link

Shared Scope does not destruct singletons in the correct order. #545

Open t-moe opened 1 year ago

t-moe commented 1 year ago

Expected Behavior

The shared scope (boost::di::extension::shared_config) destructs the singletons in the reverse order they were created.

Actual Behavior

The singletons are destructed in the order of their type_index. See https://github.com/boost-ext/di/blob/cpp14/extension/include/boost/di/extension/scopes/shared.hpp#L113-L119

Steps to Reproduce the Problem

  1. Create a injector and bind a few classes that take singletons (e.g. T&) in their constructor
  2. Use the injector to create an object
  3. Store the injector as a class member. (See also #527 )
  4. Run some code using the correctly created object and the singletons that were injected into it
  5. Delete the injector
  6. The singletons will be deleted in the wrong order

Specifications