Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Injecting problem - missing parent constructor call

I am trying to inject my BaseService within antoher service where I need to call my repository that I wrote in BaseService.

I think it's pretty simple thing but it marks __construct part with :

Missing parent constructor call

I made that logic in BaseService and it works

class BaseService
{
    /** @var ContainerInterface */
    public $container;
    public $em;

    public function __construct(ContainerInterface $container, EntityManagerInterface $em)
    {
        $this->container = $container;
        $this->em        = $em;
    }

    /**
     * @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository
     */
    public function getMyDataRepository()
    {
        return $this->em->getRepository(MyData::class);
    }
}

and my other service:

class DataService extends AbstractAdmin
{
    public function __construct(BaseService $baseService)
    {
        $this->baseService = $baseService;
    }

    public function getTransactions(Card $card)
    {
        return $this->getMyDataRepository()
            ->createQueryBuilder('c')
            ->getQuery();
    }
}
like image 872
develops Avatar asked Oct 30 '25 06:10

develops


1 Answers

I found an answer.

I did it like this:

public $baseService;

public function __construct($code, $class, $baseControllerName, BaseService $baseService)
{
    parent::__construct($code, $class, $baseControllerName);
    $this->baseService = $baseService;
}

As Abstract Admin has its constructor.

like image 135
develops Avatar answered Oct 31 '25 19:10

develops



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!