How to inject a existing component instant into another component

hi all,

I want something quite straight forward. I want a commonButComplexSingletonComponent to be injected into many other component.
Grok suggested me something like this, looks logical but does not work :

return [
    'components' => [
        'componentA' => [
            'class' => 'app\components\UserFinder',
            'someProperty' => 'value',
        ],
        'componentB' => [
            'class' => 'app\components\UserLister',
            'finder' => ['component' => 'componentA'],
        ],
        'componentC' => [
            'class' => 'app\components\UserManager',
            'finder' => ['component' => 'componentA'],
        ],
    ],
    'container' => [
        'singletons' => [
            'app\components\UserFinderInterface' => 'componentA',
        ],
    ],
];

I tried it, ‘finder’ => [‘component’ => ‘componentA’], seem to be treated as array instead of an already declared component…

I know that I can use Yii::app → get('componentA) to pass it inside setFinder… But it looks ugly. Any suggestion?

Thanks

I would use DI instead of Component injecting components.

None of these 3 is working , can you give a hints :


        'userDao' => [
            'class' => \app\user\persistent\mysql\UserDao::class,
//            'dbo' => ['component' => 'mysqlDb'] ,
        ],
        'userService' => [
            'class' => 'ngb\user\logic\UserService',
//            'userDao' => ['component' => 'userDao']
//            'userDao' => \yii\di\Instance::of('userDao'),
            'userDao' => 'userDao',  // "message": "app\\user\\logic\\UserService::setUserDao(): Argument #1 ($userDao) must be of type app\\user\\persistent\\UserDaoInterface, string given, called in /var/www/html/vendor/yiisoft/yii2/base/Component.php on line 180",