What do I need to in order to make this work?
interface BaseServiceInterface {
public function getRecords();
}
class BaseService implements BaseServiceInterface{
public function getRecords(){
return "bla";
}
}
class SomeOtherService{
private $baseService;
public function __construct(BaseServiceInterface $baseService){
$this->baseService = $baseService;
}
}
my service.yml looks like this:
base_service:
class: AppBundle\Service\BaseService
autowire: true
When I try to run this I get:
Cannot autowire argument 1 for AppBundle\Service\SomeOtherService because the type-hinted class does not exist (Class BaseServiceInterface does not exist).
autowire does not work directly with interface. you need to create the service alias to make it works.
services:
AppBundle\Service\BaseServiceInterface: '@AppBundle\Service\BaseService'
reference: https://symfony.com/doc/current/service_container/autowiring.html#working-with-interfaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With