Skip to content

Injector as class member #546

Open
Open
@ValentinNikin

Description

@ValentinNikin

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

  • Version: boost::di 1.2.0
  • Platform: debian 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions