I would like to inject to the abstract class like this:
services:
App\Infrastructure\Persistence\BaseDoctrineRepository:
arguments:
$eventStore: '@broadway.event_store'
$registry: '@doctrine'
$eventBus: '@broadway.event_handling.event_bus'
, but if do that then I get:
Cannot autowire service "App\Infrastructure\Persistence\User\DoctrineUserRepository": argument "$eventStore" of method "__construct()" references interface "Broadway\EventStore\EventStore" but no such service exists. You should maybe alias this interface to one of these existing services: "broadway.event_store.dbal", "broadway.event_store.in_memory".
So I need to duplicate code for every repository like this and I would like to avoid it.
services:
App\Infrastructure\Persistence\User\DoctrineUserRepository:
arguments:
$eventStore: '@broadway.event_store'
$registry: '@doctrine'
$eventBus: '@broadway.event_handling.event_bus'
Abstract class:
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
abstract class BaseDoctrineRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry, EventStore $eventStore, EventBus $eventBus)
{
$this->eventStore = $eventStore;
$this->eventBus = $eventBus;
parent::__construct($registry, static::REPOSITORY_CLASS);
}
Class that extends from the abastract (I would like to avoid the constructor):
class DoctrineUserRepository extends BaseDoctrineRepository implements UserRepository
{
const REPOSITORY_CLASS = User::class;
public function __construct(ManagerRegistry $registry, EventStore $eventStore, EventBus $eventBus)
{
parent::__construct($registry, $eventStore, $eventBus);
}