[Flow] Constructor injection and IDE
Mathis Hoffmann
mathis at hoffpost.de
Fri Aug 9 12:21:33 CEST 2013
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
More information about the Flow
mailing list