boost-ext / di

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

Indirect binding to constructor seems not to work correctly #534

Open mstaz opened 2 years ago

mstaz commented 2 years ago

Expected Behavior

The examples show a way to bind to a constructor and provide some constant value to it. This works in the simple case, but should also work in more complex cases.

Actual Behavior

When the binding to constructor is done indirectly via a binding to an interface, the constant values are not passed to the constructor anymore.

Steps to Reproduce the Problem

namespace di = boost::di;

struct interface {
  virtual ~interface() noexcept = default;
};

struct user : public interface
{
  explicit user(int value) {
      assert(value == 3);
  }
};

int main() {
  const auto injector = di::make_injector(
     di::bind<interface>().to<user>(),
     di::bind<user>()(3)
    );

  injector.create<interface>();
}

Link to CompileExplorer The assertion fails because value is 0. However when injector.create<user>(); is called it works just fine. Same behavior with clang and gcc.