I try to inject the $eventDispatcher in my Repository
private EventDispatcherInterface $eventDispatcher;
public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}
But since PHP 7.4 you have to be initialized. But I cant initialize the EventDispatcherInterface and get this error : Typed property $eventDispatcher must not be accessed before initialization
How can I initialize the eventDispatcher? Thanks.
Maybe, switching to Constructor Injection can solve this: