How to re-generate Magento 2 code in var/generation

- Magento 2

Magento 2 Development

First of all, I’d like to draw your attention to this blog post: Introduction to code generation in Magento 2. Having read it, you can learn more about code generation in Magento 2.

To re-generate Magento 2 code in var/generation, you should update generated code every time you upgrade Magento 2  or switch between develop and master branches of the official git repository. Although, you can manually delete content of the var/generation folder – Magento 2 will generate code automatically on its next run – the correct way requires triggering the generation via the Magento 2 CLI tool. Therefore, run magento setup:di:compile from /bin/magento:

How to re-generate Magento 2 code in var/generation