[Flow] Constructor injection and IDE

Christian Loock chl at vkf-renzel.de
Fri Aug 9 12:30:41 CEST 2013


Hi,

yeah it might be that I confused the terms. Since DI is done in the 
constructor, I always called it constructor injection vs. Setter injection.

I never use constructors in my own Classes, so I actually never came 
occrus that issue at all :D

What i usually do is, that I do my initialisation in the 
initializeObject function, which is invoked by Flow automatically.


I am still a bit confused however, why constructor parameter should be 
an issue for your IDE. Basically when using Flow, you should never need 
to instantiate a class on you own. You can write a whole application 
without using the NEW Keyword once.

Am 09.08.2013 12:21, schrieb Mathis Hoffmann:
> Hello Christian,
>
> thanks for your quick reply!
>
> But what you suggest is, as I understand everything right, not 
> constructor injection but only dependency injection in general. This 
> works in most cases but not if you have a constructor that uses the 
> injected properties. The problem is that this "standard dependency 
> injection" happens after my constructor is called. So if I for example 
> need a repository in my own constructor and call 
> $respository->findAll() I get an error that tells me that I must not 
> call findAll() on a non object. That's why I specifically need 
> constructor injection in this case.
>
> I'm not really shure weather what I just wrote ist absolutely right. 
> But looking into the generated proxy class I found that the proxy 
> first calls my original constructor and only afterwards injects the 
> properties: http://pastebin.com/GG5KAy4v
>
> Cheers
> Mathis
>
> Am 09.08.2013 11:14, schrieb Christian Loock:
>> Am 09.08.2013 11:08, schrieb Mathis Hoffmann:
>>> ng constructor parameter. I tried to set a default value 
>>> (__construct(..,.., \My\Injected\Type $parameter = null)) but that 
>>> disabled constructor injection.Does anyone have a solution for that? 
>> I dont understand that exactly.
>>
>> When you use constructor injection, you dont have to declare anything 
>> at you constructor at all. At least if I understood the concept 
>> correctly.
>>
>> You use constructor injection by using the Inject Annotation like this:
>>
>> /**
>>  * @Flow\Inject
>>  * @var TYPO3\Flow\Object\ObjectManager
>> protected $objectManager;
>>
>> You dont even need a constructor to get this work, since flow 
>> generates it in its proxy classes and does the injection magics in it.
>>
>> Im not 100% sure if this works for your example, but then also I dont 
>> get why you dont Inject everything else that gets passed to the 
>> constructor.
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow



More information about the Flow mailing list