Bug #99949
closedRepository initializeObject is never called
0%
Description
I have this code in my repository class
<?php
namespace Vendor\ExtensionName\Domain\Repository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Class ProductRepository
*/
class ProductRepository extends Repository
{
public function initializeObject()
{
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$querySettings->setLanguageOverlayMode(false);
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
...
in the controller I have
/**
* Inject the product repository
*
* @param ProductRepository $productRepository
*/
public function injectProductRepository(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
I also could notice, that this works if Dependency Injection is defined in Services.yml. But, I think, this should work also without using Services.yml
So, I would say - this is a bug or the docu https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ExtensionArchitecture/Extbase/Reference/Domain/Repository.html is not acurate.
Updated by Miladin Bojic almost 2 years ago
- Subject changed from Repository initializeObject is never calld to Repository initializeObject is never called
Updated by Torben Hansen almost 2 years ago
- Status changed from New to Needs Feedback
I do not think this is a bug, since TYPO3 extensions require a services.yaml
in order to get DI working properly. See https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/DependencyInjection/Index.html#configure-dependency-injection-in-extensions
Updated by Miladin Bojic almost 2 years ago
However, it does not work with method injection inject*(), only with constructor injection __construct() if I define arguments in Services.yaml
Maybe, I miss some configuration for it to work?
Updated by Stefan Froemken over 1 year ago
- Status changed from Needs Feedback to Closed
Hello Miladin,
thank you for providing that issue to us.
I had a look into the documentation you posted here and I have requested a patch to the documentation team:
https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/3180
I added a note to create a Service.yaml and, that you have to flush the cache in maintenance module of TYPO3.
I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.
Stefan