'Need Some more Clarification about - Initialisation of Class from Constructor and Di.xml in Magento2

  • i need to initialise the class from di.xml way(replace constructor)

  • <type name="Test\ContactUs\Plugin\Controller\Index\Post"> <arguments> <argument name="contactUsCheck" xsi:type="object">Test\ContactUs\Model\ContactUs</argument></arguments></type>

  • here I am trying to inject ContactUs Class from di.xml(argument) way. instead of directly injecting from - Constructor

  • it is not working I already define the argument name="contactUsCheck" in the constructor

    public function __construct(
     Context $context,
     ConfigInterface $contactsConfig,
     MailInterface $mail,
     DataPersistorInterface $dataPersistor,
     LoggerInterface $logger = null,
     ContactusRepositoryInterface $contactusRepository,
     $contactUsCheck
    

    ) { parent::__construct($context, $contactsConfig, $mail, $dataPersistor, $logger); $this->dataPersistor = $dataPersistor; $this->logger = $logger; $this->mail = $mail; $this->contactusRepository = $contactusRepository; $this->contactUsCheck = $contactUsCheck; }

  • Need some explanation why it is not working



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source