Boost::ex.DI - Inject parametrized object

42 views Asked by At

In our c++ application, we create many objects, like this:

class Interface {
public:
    static InterfaceImplementation Create(string s) {
        return InterfaceImplementation(s);
    }
};

class User {
public:
    User() {
        i = Interface::Create("User");
    }
private:
    Interface i;
};

Please note here, that the "User" class name and the string provided for the interface implementation match.

I would like to refactor this "pattern" and inject the interface by using e.g. Boost::ex.DI framework, but I haven't found, how to tell to the framework, to "inject instance with specific value"

class Interface {
};

class InterfaceImplementation : public Interface {
public:
    InterfaceImplementation(string s) {
    }
};

class User {
public:
    User(<Interface implementation object created by string "User">) {
    }
};

class Square {
public:
    Square(<Interface implementation object created by string "Square">) {
    }
};

Sorry, if I missed something from the documentation.

0

There are 0 answers