[TYPO3-mvc] How should/can I pass parameters to an object's constructor using dependency injection?

Marc Bastian Heinrichs typo3 at mbh-web.de
Fri Nov 19 16:49:47 CET 2010


Hi Simon,

> As you can see I have a class "ThisClass" which needs to inject 
> "ThatClass", but ThatClass's constructor takes an argument. If ThatClass 
> hasn't been instantiated how will the the DI container be able to 
> instantiate ThatClass without being passed it's constructor parameter? 
> Are you saying the DI container will automatically "get" the constructor 
> parameter for ThatClass and that I cannot pass the parameter for 
> ThatClass's constructor to the DI container?

If Tx_YourExt_SomeClass is an singleton as well, DI injects $someObject
by contructor injection. If it's of scope prototype you need an other
solution to set $someObject in $thatClass.

Regards,
Marc Bastian



More information about the TYPO3-project-typo3v4mvc mailing list