di icon indicating copy to clipboard operation
di copied to clipboard

Multiple binding of value

Open Warchant opened this issue 6 years ago • 2 comments

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

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

boost::di::bind<Interface*[]>.to(values) // <--

Warchant avatar Jul 17 '19 20:07 Warchant

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>()
  );

kanstantsin-chernik avatar Oct 14 '19 17:10 kanstantsin-chernik

@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

KilianBl avatar Sep 14 '22 09:09 KilianBl