boost-ext / di

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

Multiple binding of value #430

Open Warchant opened 5 years ago

Warchant commented 5 years ago

Is it possible to bind a vector of instances like that?

std::vector<std::shared_ptr<Interface>> values = {...};

boost::di::bind<Interface*[]>.to(values) // <--
kanstantsin-chernik commented 4 years ago

I did some experiments and don't see it working.

There is an example with ints but it doesn't fork for array.

However, you still can use DI for interface bindings like this:

  auto injector = di::make_injector(
    di::bind<i1*[]>().to<impl, impl1>()
  );
KilianBl commented 2 years ago

@Warchant @kanstantsin-chernik Did you find any workaround to this problem using already created instances?

The vector seems to be default-constructed and the instance passed to di::bind is not used.

Thanks in advance