81188[WIP][FEATURE] Use DI to autoconfigure extbase repositories
Commit message
Test this change
Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch
- Check out patch set 9
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/88/81188/9 && git checkout FETCH_HEAD - Cherry-pick onto main
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/88/81188/9 && git cherry-pick FETCH_HEAD
Review
-
Code review CR 0 Needs a vote
-
Verified V 0 Needs a vote
- core-ci +1 CI
Merge conflicts 4
Issues 1
Files 6
- typo3/sysext/core/Documentation/Changelog/14.0/Feature-102027-UseDependencyInjectionToAutoconfigureExtbaseRepositories.rstnew+48 −0
- typo3/sysext/extbase/Classes/DependencyInjection/RepositoryPass.php7new+67 −0
- typo3/sysext/extbase/Classes/Persistence/Repository.php5+5 −3
- typo3/sysext/extbase/Configuration/Services.php+3 −0
- typo3/sysext/extbase/Configuration/Services.yaml1+3 −0
- typo3/sysext/styleguide/Classes/DummyDumpContentProvider.php+1 −1
Review log 2130
Show 45 earlier messages
-
Alexander Schnitzler uploaded patch set 1 09/24/23, 14:37
-
core-ci voted on patch set 1 V -1 09/24/23, 14:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47122
-
Alexander Schnitzler uploaded patch set 2
V -109/25/23, 06:04 -
Alexander Schnitzler commented on patch set 2 09/25/23, 06:05
-
Alexander Schnitzler wrote 09/25/23, 06:05
Topic set to extbase
-
core-ci voted on patch set 2 V +1 09/25/23, 06:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47133
-
Alexander Schnitzler uploaded patch set 3
V +109/27/23, 05:58 -
Alexander Schnitzler uploaded patch set 4 09/27/23, 05:59
-
core-ci voted on patch set 3 V +1 09/27/23, 06:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47204
-
core-ci voted on patch set 4 V +1 09/27/23, 06:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47205
-
Benjamin Franzke uploaded patch set 5
V +109/27/23, 09:00 -
Benjamin Franzke commented on patch set 5 09/27/23, 09:00
Looks good in general, only some minor docs remarks.Feature-102027-UseDIToAutoconfigureExtbaseRepositories.rst:6Let's use long form "dependency injection" in Feature titlesFeature-102027-UseDIToAutoconfigureExtbaseRepositories.rst:23I think this section is good for a commit message, but the Feature.rst description doesn't need to describe the details of the internal constructur changes. We should rather describe how to be migrate in a forward/backwards compatible way (though that's probably best added to a separate Deprecation.rst), like: public function __construct(private readonly SomeDependency $someDep, string $entityClass = null) { parent::__construct($entityClass); }Feature-102027-UseDIToAutoconfigureExtbaseRepositories.rst:64We usually use Services.yaml examples in documentation.Feature-102027-UseDIToAutoconfigureExtbaseRepositories.rst:66The services autoconfiguration doesn't need to be fulled turned of, setting the argument is enough (with your current Pass implementation, and that is fine/good)RepositoryPass.php:39ReplyDoneRepositoryPass.php:39ReplyDoneRepositoryPass.php:42Hm, so this is a workaround because we actually never want `TYPO3\CMS\Extbase\Persistence\Repository` to be instantiated/configured at all, right? (it should actually be an abstract class) We can be more explicit in our config and mark this service to not be available via `autoconfigure: false` in `Services.yaml` Even better would be to actually use `abstract class`. I think that would not even be breaking, as `Repository` couldn't be used as distinct service anyway as `objectType` was not writable. What do you think?RepositoryPass.php:51A check is needed if the class actually accepts an argument named `$entityClass`, otherwise a compile time error appears for existing repositories that use constructor based dependency injection (so do not yet have $entityClass defined): Invalid service "MyVendor\MyExtension\Domain\Repository\MyRepository": method "__construct()" has no argument named "$entityClass". Check your service definition.Repository.php:63Let's add a proper deprecation right away. I've marked that as TODO in the commit message. -
core-ci voted on patch set 5 V -1 09/27/23, 09:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47219
-
Benjamin Franzke uploaded patch set 6
V -109/27/23, 09:25 -
core-ci voted on patch set 6 V +1 09/27/23, 09:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47220
-
Alexander Schnitzler commented on patch set 6 09/27/23, 16:21
Feature-102027-UseDIToAutoconfigureExtbaseRepositories.rst:23ReplyAckRepositoryPass.php:42ReplyI agree, Repository should be abstract but I wasn't sure if this is considered breaking and I want to avoid a breaking rst and the scanner shizle.Repository.php:63ReplyFine for me. -
Alexander Schnitzler marked it work in progress 09/27/23, 16:21
-
Garvin Hicking uploaded patch set 7
V +109/30/25, 18:44 -
Garvin Hicking marked it ready for review 09/30/25, 18:45
-
core-ci voted on patch set 7 V -1 09/30/25, 18:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/85756
-
Garvin Hicking uploaded patch set 8
V -109/30/25, 19:06 -
core-ci voted on patch set 8 V +1 09/30/25, 19:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/85757
-
Garvin Hicking commented on patch set 8 09/30/25, 19:17
(rebased, moved ReST file - I think this one could be carried over to the finish line?)RepositoryPass.php:42ReplyI've declared the repository as 'abstract'. I wouldn't know cases where a direct repository class gets instantiated without getting extended from `Repository`. So I would agree this should not be breaking.Repository.php:63ReplyHhhhhm. I'm a bit unsure about this. Do I understand this right, that would require developers to never do a "new DummyRepository()" anywhere? I think this could affect a few people, and the "annoyance" to explicitly configure coupled entity classes to a repository might be impactful. I would like to continue having some Extbase convenience in my DX, and would appreciate an "opt in" to decoupling namespaces here. I think our usual recommendation to follow extbase conventions here is followed by many developers, and I believe in the usual cases, developers will keep their "couple by naming scheme". Using DI is still hard for a lot of extbase developers and integrators I know, despite all the length we've gone through to advocate it. Doing this without a real-life gain in migrations feels unlucky to me. -
Garvin Hicking voted on patch set 8 CR +1 09/30/25, 19:17
-
Stefan Bürk commented on patch set 8 10/01/25, 10:52
Repository.php:63Reply@garvin@hick.ing `new DummyRepository()` does not work anyway, as all the `inject*` method injection is not executed and missing persistancemenanger and event manager already. It should be at least `GeneralUtility::makeInstance()` getting it from the DI. @git@alexanderschnitzler.de @ben@bnf.dev However, I'm not sure about making the constructor API now with a scalar value, first optional and later (v15) mandantory. That means, that custom repositories extending this base class needs to ensure to have the "same" argument provided and calling the parent with it, and future additions to the constructor is considerable breaking special for non optionale arguments. In case the custom repository overrides the constructor, not having it in place it's okay in v14, but makint it not-nullable in v15 would lead to ``` Typed property Repository::$entityClass must not be accessed before initialization ``` I'm getting the intention and use-case, but maybe we should have that as a setter method keeping the fallback to calculate the matching domain model, or we need to communicate and making the constructor final (not the class) and developers implementing own repository classes based on this (abstract/base) needs to use inject methods then instead of constructor DI. At least we must be sure what we want in the Repository constructor and commenting it that changes are considerable breaking and can only be changed for `*.0` realeases as breaking if not made final. Not into the smyfony configurator thing but maybe that could be an option to avoid making the constructor api ? Another solution staying on a "setter" method (which the pass could set if not defined as call): https://symfony.com/doc/current/service_container/calls.html ``` services: SBUERK\DiTests\Services\ExampleRepository: public: true calls: - withClassName: - 'custom-class-name-value' ``` Arguments needs to be provided as array then (not sure / tested if named argument mapping can be done. The #[Required] attriubute could be added to setter (wither) enforcing that the call needs to be configured (not tested, but can be provided by the compiler pass eventually ?). ``` If autowire is enabled, you can also use attributes; with the previous example it would be: use Symfony\Contracts\Service\Attribute\Required; #[Required] public function withLogger(LoggerInterface $logger): static { $new = clone $this; $new->logger = $logger; return $new; } If you don't want a method with a static return type and a #[Required] attribute to behave as a wither, you can add a @return $this annotation to disable the returns clone feature. ``` -
Benjamin Franzke uploaded patch set 9
CR +1V +110/01/25, 12:02 -
Benjamin Franzke commented on patch set 9 10/01/25, 12:02
Services.yaml:40Can be removed as these dependencies are wired via PHP attributes inside the classes, this must be a rebasing mistake. -
core-ci voted on patch set 9 V +1 10/01/25, 12:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/85812
-
Stefan Bürk commented on patch set 9 10/01/25, 21:01
Repository.php:63Reply UnresolvedAlternative approach -> https://review.typo3.org/c/Packages/TYPO3.CMS/+/90860 ... -
Benni Mack marked it work in progress 04/21/26, 15:15
RepositoryPass.php:39