I see that Magento 2 has 3 factory classes (4 if you count the abstract one).

  • \Magento\Framework\ObjectManager\Factory\Dynamic\Developer
  • \Magento\Framework\ObjectManager\Factory\Dynamic\Production
  • \Magento\Framework\ObjectManager\Factory\Compiled

All of the above extend \Magento\Framework\ObjectManager\Factory\AbstractFactory.
I assumed that when on developer mode, the Developer factory would be used, but sometimes the Compiled one is used and I cannot pinpoint the conditions for this.

Can someone please explain when each factory is used and what are the differences between them?

1 Answer 1


And condition is here: \Magento\Framework\App\EnvironmentFactory::createEnvironment

It does check if file with compiled content is exist for current area: "/var/di/global.ser", "/var/di/frontend.ser" and "/var/di/adminhtml.ser" correspondingly.

The difference is in performance of Object Manager. Constructor dependencies and plugins information is serialized in those files, so Object Manager instantiating objects faster, without using Reflection and calculating chains of dependencies. And doesn't matter if your instance is running in developer or other mode. Object Manager factory is resolved based on availability of those files only. If file for corresponding area is available then "Compiled" factory is used, if file is not available then "Developer" factory is used instead. And "Production" factory is left out and will be removed from the code base.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.