Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple binding of value #430

Open
Warchant opened this issue Jul 17, 2019 · 2 comments
Open

Multiple binding of value #430

Warchant opened this issue Jul 17, 2019 · 2 comments
Labels

Comments

@Warchant
Copy link

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
Copy link
Collaborator

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
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants