I have created an interface, I'm trying to inject it inside Controller. But I'm getting following error:
Argument 1 passed to backend\controllers\AgencyController::__construct() must implement interface common\service\AppServiceInterface, string given
I created service folder inside common folder, added two files into it
- AppService.php
- AppServiceInterface.php
Now I defined this dependency inside common/bootstrap.php
file as below:
Yii::$container->set('common\service\AppServiceInterface',
'common\service\AppService');
Afterwards I tried to inject it inside AgencyController which is placed inside backend/controllers/AgencyController like below:
namespace backend\controllers;
use common\service\AppServiceInterface;
public function __construct(AppServiceInterface $appService)
{
$this->appService = $appService;
}
But I'm getting the error as mentioned earlier.