ZF2-261: Zend DI Factory Method called twice
When using a factory method with a parameter definition to create a class the factory method will be called twice:
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.