我试图将一个服务注入另一个服务以从中调用函数,但它引发了一个错误:
类型错误:传递给 App\Base\Service\Shop\ShopService::__construct() 的参数 1 必须是 App\Base\Service\AccountService 的实例,ContainerSgqv3vy\appDevDebugProjectContainer 的实例
我认为我正确地实现了一切:
use App\Base\Service\AccountService;
use App\Base\Service\BaseService;
class ShopService extends BaseService
{
/**
* @param AccountService $accountService
*/
public function __construct(AccountService $accountService)
{
parent::__construct();
$this->accountService = $accountService;
}
并从中调用我的函数:
this->accountService->getMyFunction();
我的实例化类:
class BaseService
{
/** @var ContainerInterface */
var $container;
var $em;
public function __construct(ContainerInterface $container, EntityManagerInterface $em)
{
$this->container = $container;
$this->em = $em;
}
服务.yml
app.shop:
class: App\Base\Service\ShopService
arguments: ["@service_container", "@doctrine.orm.default_entity_manager"]
public: true
ITMISS