Task #87305

Epic #87275: Use constructor injection in core extensions

Use constructor injection in DataMapper

Added by Alexander Schnitzler over 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
Should have
Category:
Code Cleanup
Target version:
-
Start date:
2018-12-30
Due date:
% Done:

100%

TYPO3 Version:
10
PHP Version:
7.3
Tags:
Complexity:
Sprint Focus:

Related issues

Related to TYPO3 Core - Bug #91200: Extbase DataMapper can not be injected because of QueryInterface constructor dependency Closed 2020-04-26

Associated revisions

Revision 5b47cc8b (diff)
Added by Alexander Schnitzler over 1 year ago

[TASK] Use constructor injection in DataMapper

Class DataMapper does no longer use setter injection but
constructor injection instead.

Releases: master
Resolves: #87305
Change-Id: I88596a5e2e22deb8d11f6d83901c2c660b81bf0c
Reviewed-on: https://review.typo3.org/59279
Tested-by: TYPO3com <>
Reviewed-by: Mona Muzaffar <>
Tested-by: Mona Muzaffar <>
Reviewed-by: Anja Leichsenring <>
Tested-by: Anja Leichsenring <>

Revision 3c6d295a (diff)
Added by Benjamin Franzke about 1 month ago

[TASK] Provide dependency injection configuration for extbase DataMapper

The extbase DataMapper was changed to use constructor based
dependency injection with change #87305. The argument $query
(of type QueryInterface) was set to a nullable
and way therefore ignored by the Extbase ObjectManager.

This class is currently only used via the Extbase ObjectManager
in core. It was therefore excluded from the symfony dependency
injection and therefore never fataled during symfony DI
container build.

Symfony DI does – in contrast to extbase DI – inject nullable
constructor arguments.
That means:
Once core or an extension starts to inject this service,
injection will fail, as QueryInterface points to the Query object
which is not autowirable. (see exception below)

Note: While it is not supported that extensions inject
this internal service, we still fix this case, because the
exception is a) hard to debug und b) core may inject it in
future.

The service is also declarted to be a prototype (shared: false) as it may
contain state, as set via `setQuery`.

[1] exception thrown by symfonyduring DI compilation:
Symfony\Component\DependencyInjection\Exception\RuntimeException:
Cannot autowire service "TYPO3\CMS\Extbase\Persistence\Generic\Query":
argument "$type" of method "__construct()" has no type-hint,
you should configure its value explicitly.

Releases: master
Resolves: #91200
Related: #87305
Change-Id: I58b1cff94136a4170fb7e6712470069a141940b7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64319
Tested-by: TYPO3com <>
Tested-by: Sebastian Fischer <>
Tested-by: Alexander Schnitzler <>
Reviewed-by: Sebastian Fischer <>
Reviewed-by: Alexander Schnitzler <>

History

#1 Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59279

#2 Updated by Gerrit Code Review over 1 year ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59279

#3 Updated by Anonymous over 1 year ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#4 Updated by Benni Mack 11 months ago

  • Status changed from Resolved to Closed

#5 Updated by Benjamin Franzke about 1 month ago

  • Related to Bug #91200: Extbase DataMapper can not be injected because of QueryInterface constructor dependency added

Also available in: Atom PDF