Review main Abandoned

59254[WIP][TASK] Use constructor injection instead of setter injection

Alexander Schnitzler CR 0 V 0 Expert +1286 −1035 updated 02/04/19, 08:54

Commit message

Constructor injection clearly shows the dependencies of objects
and therefore is the preferred way of declaring dependencies.

Thus, the whole core should use constructor injection. Not only
to define better visibility but also as a first step for the
introduction of a proper DI mechanic.

Review

  • Code review CR 0
  • Verified V 0

Files 102

Show 82 more files

Review log 812

  1. Alexander Schnitzler uploaded patch set 1 12/21/18, 10:05

  2. TYPO3com voted on patch set 1 V +1 12/21/18, 10:16 Completed build in 10m 53s on Fri, 21 Dec, 11:16 AM Test Summary: 48261 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-31020

  3. Alexander Schnitzler commented on patch set 1 CR -1 12/21/18, 10:25

    Just a first example for now to show how the changes look like.
  4. Alexander Schnitzler uploaded patch set 2 12/21/18, 22:59

  5. TYPO3com voted on patch set 2 V -1 12/21/18, 23:10 Completed build in 10m 42s on Sat, 22 Dec, 12:10 AM Test Summary: 1591 of 48575 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-31054

  6. Alexander Schnitzler uploaded patch set 3 12/21/18, 23:32

  7. TYPO3com voted on patch set 3 V -1 12/21/18, 23:43 Completed build in 10m 50s on Sat, 22 Dec, 12:43 AM Test Summary: 1419 of 48575 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-31056

  8. Alexander Schnitzler uploaded patch set 4 12/21/18, 23:57

  9. TYPO3com voted on patch set 4 V -1 12/22/18, 00:07 Completed build in 09m 49s on Sat, 22 Dec, 01:07 AM Test Summary: 1267 of 48575 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-31057

  10. Benjamin Franzke commented on patch set 4 12/22/18, 04:36

    I do also favor constructor based injection – setter injection is ugly, especially the need for writing construction code into a separate intializeObject() method – but: Setter injection is *not* a blocker for a proper DI mechanic. The proof of concept – which i'm still working on to get merged – that I showed you back in September demonstrates that inject* methods (plus initializeObject) are easily doable with symfony DI compiler passes: https://review.typo3.org/c/58255/21 Furthermore I do see a need for setter injection – the much I hate to say that – in a modular ecosystem like TYPO3: Base classes that are @api, need the flexibility to add new dependencies without going through a deprecation process, otherwise the progress is slowed down. I'm fine when this gets merged as code cleanup, but be aware: a) That changes like these (changes constructor arguments, removed inject methods) were all considered breaking during the v9 development and needed deprecations, so others would want to see a lot of deprecations here. b) That this change will make backports to v9 harder. c) This can not be merged with the argument "for a proper DI", it is personal taste; it is "code cleanup" d) I don't think we can drop setter based injection altogether. When we talked earlier this year (together with susi), we defined that it is a requirement for a new DI to keep existing extbase users on track. Instructing them to rewrite all classes to use constructor injection instead of inject methods (not long after they migrated from property to setter injection), is nearly as bad as if we would say: We drop autowiring! (which I would also like, but I do see the need for it in a big ecosystem like TYPO3) So I think we should stick with the situation that we have and accept that setter injection needs to be supported.
  11. Alexander Schnitzler commented on patch set 4 12/22/18, 09:01

    Hi Benjamin, there are no plans to drop setter injection. So, there will be no need for anyone to move from setter injection to constructor injection, just like we didn't force anyone yet to move from property injection to setter injection. We do recommend using this or that but so far, people didn't have to adjust their code once. I also understand that setter injection is proper DI as well. What I try to achieve with this patch is the following: - Show dependencies between objects - Show, which tests do not actually test whole objects but just part of it or which actually test dependencies. (Especially in Extbase we have super complex unit tests with dozens of mocks and it is all hidden at the moment. - Detect where the container aka ObjectManager is injected instead of actual dependencies. - See, which objects that are no services are treated as such. (entities for example) As you can see, this change is already way too big with still over 1000 failing tests. This is a test so far. I will split this patch into smaller parts, beginning with non-api code, so we have as little impact as possible. I understand all your concerns and I share them. Thanks for your feedback.
  12. Alexander Schnitzler abandoned the change 02/04/19, 08:54

    Patch will be split into smaller chunks.