This is a common misconception:
Not every class you use in TYPO3 CMS uses dependency injection by default - and it's a good thing.
What is true, is that every object that has been instantiated by the ObjectManager can benefit from it.
In short: if you new Thing()
some object, it won't benefit from dependency injection. If you use the ObjectManager
to get an instance of something, the whole dependency injection gallore will rain down on your new instance:
- constructor injection [Example: How can I use an injected object in the constructor?
- annotations are read and field injections are done
- setter injection was done in the past (Remark: I think it's deprecated)
- public method (if existent)
initializeObject
is called
Note that injected objects are being instantiated by the objectManager as well-so recursion is possible if injected ServiceA
needs an injected ServiceB
.
Singletons are possible as well if you implement the marker interface SingletonInterface
.