I'm performing an upgrade to Magento 2.4 and the registry class has been deprecated but it's being used in some custom modules, please see the code below:
<?php declare(strict_types=1);
namespace TP\Cars\Model;
use TP\Cars\Model\ResourceModel\Facility\Collection;
use TP\CarsApi\Api\Data\FacilityInterface;
use TP\CarsApi\Api\Data\FacilityInterfaceFactory;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Registry;
class Facility extends AbstractModel
{
protected $_eventPrefix = 'TP_vehicle_facility';
private DataObjectHelper $dataObjectHelper;
private FacilityInterfaceFactory $facilityDataFactory;
/**
* @param array<mixed> $data
*/
public function __construct(
Context $context,
Registry $registry,
FacilityInterfaceFactory $facilityDataFactory,
DataObjectHelper $dataObjectHelper,
ResourceModel\Facility $resource,
Collection $resourceCollection,
array $data = []
) {
parent::__construct(
$context,
$registry,
$resource,
$resourceCollection,
$data
);
$this->facilityDataFactory = $facilityDataFactory;
$this->dataObjectHelper = $dataObjectHelper;
}
public function getDataModel(): FacilityInterface
{
$facilityData = $this->getData();
$facilityDataObject = $this->facilityDataFactory->create();
$this->dataObjectHelper->populateWithArray(
$facilityDataObject,
$facilityData,
FacilityInterface::class
);
return $facilityDataObject;
}
}
Can you suggest how I can eliminate the use of the registry class?