google / google/fruit

Using factory parameter in a nested class

Open
#130 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
202
PR merge metrics
No merged PRs in 30d

Description

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 getInnerClassComponent(const TypeEnum type)
{
switch (type)
{
case TypeEnum::A: return getType1Component();
// etc
}
```

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.