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

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?

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