Can't inject repository on some controller Typo3

1.2k views Asked by At

In my custom controller, i'm trying to inject a repository as a dependecy, like this

class FundedProjectController extends ActionController {


    /**
     * @var \GeorgRinger\News\Domain\Repository\NewsRepository
     */
    protected $newsRepository;


    /**
     * Inject a news repository to enable DI
     *
     * @param \GeorgRinger\News\Domain\Repository\NewsRepository $newsRepository
     */
    public function injectNewsRepository(\GeorgRinger\News\Domain\Repository\NewsRepository $newsRepository)
    {
        $this->newsRepository = $newsRepository;
    }
...

But when I call it in my previewAction, i have an error saying that my $this->newsRepository is null.

But this injection is working on this controller, but I can't figure out why...

class NewsController extends NewsBaseController

I'm working on 7.6.32, stagging website but production mode enable, all caches cleared (also tried with ?no_cache=1, also tried with "@inject"

1

There are 1 answers

3
User366 On

TYPO3 now requires to configure dependency injection. It does not work automatically any more. Basically you need to add a special Configuration/Services.yaml file. See here how to configure it.