ZF2-261: Zend DI Factory Method called twice
Description
When using a factory method with a parameter definition to create a class the factory method will be called twice:
Example:
return array(
'di' => array(
'definition' => array(
'class' => array(
'MyClass' => array(
'instantiator' => array('MyClass', 'create'),
'methods' => array(
'create' => array(
'param' => array('type' => 'MyOtherClass', 'required' => true),
),
),
),
),
),
),
);
MyClass will be created during Di::newInstance by Di::createInstanceViaCallback(). If the instantiator method is "__construct" the "__construct"-method will be removed from the array of possible injection methods ($injectionMethods). If the instantiator is something different, the method (in the example "create") will NOT be removed. So the method is called again from Di::handleInjectionMethodForInstance() which results in a second instance of MyClass.
Comments
Posted by Ralph Schindler (ralph) on 2012-06-25T21:27:52.000+0000
I am closing the related pull request, with the information above, this is hard to follow your use case, can you provide more information and/or a unit test?
Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:21.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2470