-
Notifications
You must be signed in to change notification settings - Fork 138
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
DI Runtime Injector fails to compile for bind to a value #535
Comments
This code doesn't look valid to me. You have to tell bind what you're binding, with a type argument. This version builds and runs on latest MacOS 12.4.
|
Hi @xoltar , thanks for your prompt reply the code that you mentioned does work. But I noticed that we can't still bind to an instance where its lifetime is controlled by the user in case of using a runtime dependency injector. Can we actually pass a defined instance to a runtime injector? #include <boost/di.hpp> using namespace boost::di; struct A { int main(int argc, char** argv) std::cout << "now: " << b.now() << std::endl; |
Is there a way to bind a existed instance to a type using runtime_injector, like this ? void fun() { ` |
Expected Behavior
Should compile
Actual Behavior
/Users/hafshari/.conan/data/di/1.2.0/jenkins-clt/stable/package/964905e09401b68ee5f6b695b187d4fa9eb760c2/include/boost/di/extension/providers/runtime_provider.hpp:125:14: error: call to member function 'make' is ambiguous
return make(binding);
^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:15:11: note: in instantiation of function template specialization 'boost::di::extension::detail::injector<boost::di::extension::assert_error_policy, boost::di::extension::shared_config>::install<boost::di::core::dependency<boost::di::scopes::instance, A>, 0>' requested here
injector.install(bind.to(A(1)));
^
/Users/hafshari/.conan/data/di/1.2.0/jenkins-clt/stable/package/964905e09401b68ee5f6b695b187d4fa9eb760c2/include/boost/di/extension/providers/runtime_provider.hpp:158:8: note: candidate function [with T = A, TBinding = boost::di::core::dependency<boost::di::scopes::instance, A>]
auto make(const TBinding &) -> decltype(make_impl(typename ctor_traits::type{})) {
^
/Users/hafshari/.conan/data/di/1.2.0/jenkins-clt/stable/package/964905e09401b68ee5f6b695b187d4fa9eb760c2/include/boost/di/extension/providers/runtime_provider.hpp:163:8: note: candidate function [with T = A, TBinding = boost::di::core::dependency<boost::di::scopes::instance, A>]
auto make(const TBinding &binding) -> decltype(new T{binding.object_}) {
^
1 error generated.
make: *** [main] Error 1
Steps to Reproduce the Problem
#include <boost/di.hpp>
#include <boost/di/extension/providers/runtime_provider.hpp>
using namespace boost::di;
struct A {
A(int) {};
virtual int now() {return 1;};
};
int main()
{
auto inj = make_injector();
extension::runtime_injector injector;
injector.install(bind.to(A(1)));
return 0;
}
Specifications
The text was updated successfully, but these errors were encountered: