This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param \Magento\Framework\Model\Context $context | |
* @param \Magento\Framework\Registry $registry | |
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory | |
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory | |
* @param \Magento\Directory\Helper\Data $directoryData | |
* @param \Magento\Eav\Model\Config $eavConfig | |
* @param Address\Config $addressConfig | |
* @param \Magento\Directory\Model\RegionFactory $regionFactory | |
* @param \Magento\Directory\Model\CountryFactory $countryFactory | |
* @param AddressMetadataInterface $metadataService | |
* @param AddressInterfaceFactory $addressDataFactory | |
* @param RegionInterfaceFactory $regionDataFactory | |
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper | |
* @param CustomerFactory $customerFactory | |
* @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor | |
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry | |
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource | |
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection | |
* @param array $data | |
* | |
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | |
*/ | |
public function __construct( | |
\Magento\Framework\Model\Context $context, | |
\Magento\Framework\Registry $registry, | |
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, | |
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, | |
\Magento\Directory\Helper\Data $directoryData, | |
\Magento\Eav\Model\Config $eavConfig, | |
\Magento\Customer\Model\Address\Config $addressConfig, | |
\Magento\Directory\Model\RegionFactory $regionFactory, | |
\Magento\Directory\Model\CountryFactory $countryFactory, | |
AddressMetadataInterface $metadataService, | |
AddressInterfaceFactory $addressDataFactory, | |
RegionInterfaceFactory $regionDataFactory, | |
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper, | |
CustomerFactory $customerFactory, | |
\Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, | |
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, | |
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, | |
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, | |
array $data = [] | |
) { | |
$this->dataProcessor = $dataProcessor; | |
$this->_customerFactory = $customerFactory; | |
$this->indexerRegistry = $indexerRegistry; | |
parent::__construct( | |
$context, | |
$registry, | |
$extensionFactory, | |
$customAttributeFactory, | |
$directoryData, | |
$eavConfig, | |
$addressConfig, | |
$regionFactory, | |
$countryFactory, | |
$metadataService, | |
$addressDataFactory, | |
$regionDataFactory, | |
$dataObjectHelper, | |
$resource, | |
$resourceCollection, | |
$data | |
); | |
} |
Magento\Customer\Model\Address
I know there are some disadvantages in usage of DI-Container. But a good architecture allows contextbased DI-Container, to prevent this kind of constructor mess. It could sound oldschool, but more then 3 parameter in a constructor is smelly.
This constrcutor contains 18 Parameters.
7 of the parameter are factories. I think its a good idea, to group the factories in a dedicated factory-di-container.
2 of are configobjects
2 are registries
1 Service
and so on.
Thats realy hard to learn and to refactore, if you have to change somethig in there.
What is best practice to prevent that?
Keine Kommentare:
Kommentar veröffentlichen