google / fruit

Fruit, a dependency injection framework for C++

Home Page:https://github.com/google/fruit/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing reference parameters to get*Component functions doesn't work

poletti-marco opened this issue · comments

Test case:

#include <fruit/fruit.h>
fruit::Component<int> getRootComponent(int& n) {
   return fruit::createComponent().bindInstance(n);
}
static int n = 3;
int main() {
    fruit::Injector<int> injector(getRootComponent, n);
    injector.get<int>();
}

It should work, or at the very least it should fail with an error message mentioning this workaround:

#include <fruit/fruit.h>
fruit::Component<int> getRootComponent(int* n) {
   return fruit::createComponent()
        .bindInstance(n);
}
static int n = 3;
int main() {
    fruit::Injector<int> injector(getRootComponent, &n);
    injector.get<int>();
}