TYPO3 symfony dependency injection: Nested services injection with interface implementation

Viewed 26

I have the following php classes:

class A
{
    private SomeInterface $interfaceImpl;

    public function __construct(SomeInterface $interfaceImpl)
    {
        $this->interfaceImpl = $interfaceImpl;
    }
}

class B
{
    private A $classA;

    public function __construct(A $classA)
    {
        $this->classA = $classA;
    }
}

class InterfaceImplA implements SomeInterface {}
class InterfaceImplB implements SomeInterface {}
class InterfaceImplC implements SomeInterface {}

TYPO3 v11 with symfony dependency injection is used here.

SomeInterface has multiple implementations. Depending on where class A is used different implementations of SomeInterface are needed. So I need a dedicated implementation injected into class A when it is injected into class B.

How can I configure Services.yaml correctly to use one of those implementations injected into class A only when class A is injected into class B? I must not set this globally to avoid, that always the same implementation is injected into class A at any other place. Is this possible somehow?

Thank you very much for answers!

Environment: TYPO3 v11

0 Answers
Related