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

Dynamic bindings don't work with explicit singleton scope #548

Open
scztt opened this issue Apr 27, 2023 · 0 comments
Open

Dynamic bindings don't work with explicit singleton scope #548

scztt opened this issue Apr 27, 2023 · 0 comments

Comments

@scztt
Copy link

scztt commented Apr 27, 2023

Expected Behavior

#include <boost/di.hpp>

struct trivial{};
struct trivial_impl : public trivial {};

int main() {
  const auto injector = boost::di::make_injector(
        boost::di::bind<trivial>.to([](auto const& inj) -> std::shared_ptr<trivial> {
            return inj.template create<std::shared_ptr<trivial_impl>>();
        })
        // does not compile
        // .in(boost::di::singleton)
  );

  auto t = injector.create<std::shared_ptr<trivial>>();
}

(https://godbolt.org/z/rzvja1PqM)

My expectation is that uncommenting the .in line is valid and should compile. Moreover, my impression is that singleton scope is the default, so this code should be semantically identical with or without the commented line.

Actual Behavior

Compile error related to "creatable constraint not satisfied". None of the obvious alternative return values from the lambda work here, nor do obvious variations on the create call (e.g. create<trivial&>). The above failure also applies to other scopes like extension::session, but this may be because they wrap singleton.

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

No branches or pull requests

1 participant