0

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.

Moravas
  • 79
  • 6
  • 1
    Can you supply a minimal self-contained example? Preferrably showing what you've tried and where you are stuck – sehe Sep 30 '22 at 12:05
  • The minimal example - at least the expectation is above. I'm at the beginning of the investigation, I haven't started yet to refactor our product – Moravas Sep 30 '22 at 12:22
  • It lacks all reference to Boost.DI and the moving parts that we need to know when it's working/satisfying the requirements – sehe Sep 30 '22 at 12:26

0 Answers0