Magento will generate any class with 'Factory' on the end itself either on the fly in developer mode or as part of the setup:di:compile
process. The factory class will have a method called create
that will instantiate a new instance of the class on it.
A normal example in a setup class would be as below.
use Magento\Framework\Setup\InstallDataInterface;
class Setup implements InstallDataInterface {
protected $eavSetupFactory;
public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(\Magento\Framework\Setup\InstallDataInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
{
/**
* @var \Magento\Eav\Setup\EavSetup $eavSetupModel
*/
$eavSetupModel = $this->eavSetupFactory->create(['setup' => $setup]);
}
}
This is typically used so that you can load a model using dependency injection. Rather than request Magento\Eav\Setup\EavSetup
, you request Magento\Eav\Setup\EavSetupFactory
and then call the create method to get you the Magento\Eav\Setup\EavSetup
object.