Skip to content

Using factory parameter in a nested class #130

@Simmay93

Description

@Simmay93

Hi there,

I have the following problem:
I have a class with an assisted parameter and a component in the constructor. The assisted variable is needed for the construction of the component. How can I solve this problem. I did not find a straight forward solution in the wiki.

class OuterClass {
  public INJECT(OuterClass(ASSISTED(const TypeEnum) type, IClass* innerClass));
};

for the innerClass I have a method which returns an actual class according to the type:

fruit::Component<IClass> getInnerClassComponent(const TypeEnum type)
{
  switch (type)
  {
    case TypeEnum::A: return getType1Component();
    // etc
}

the factory looks like this:

fruit::Component<OuterClassFactory> getOuterClassComponent()
{
  return fruit::createComponent().bind<IOuterClass, OuterClass>().install(getInnerClassComponent, TypeEnum::A); // <-- here I want to use the param with which the factory is called
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions