boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.13k stars 136 forks source link

Injector as class member #546

Open ValentinNikin opened 1 year ago

ValentinNikin commented 1 year ago

I have the configured injector, for example like this

auto injector = boost::di::make_injector(
            boost::di::bind<AgentsController>().in(boost::di::unique),
            boost::di::bind<AgentCommunicatorController>().in(boost::di::unique),
            boost::di::bind<IAgentsManager>.to<WorkflowManager>().in(boost::di::singleton),
            boost::di::bind<IAgentCommunicator>.to<WorkflowManager>().in(boost::di::singleton)
            );

I want to write Types Factory with this injector, something like this. But the question is what type should injector member be?

class TypesFactory {
public:
    template<typename T>
    T resolve() {
        return _injector.create<T>();
    }
private:
SomeTypeOfInjector _injector; <---- What type should SomeTypeOfInjector be?
}

Specifications