2

How to solve the following circular dependency error?

This is my class:

class QueueFactory extends \Magento\Framework\Model\AbstractModel
{
   protected $syncQueueFactory;

   public function __construct(
    QueueFactory $syncQueueFactory,
   array $data = []
   ) {
      $this->syncQueueFactory = $syncQueueFactory;
      $this->_queue = $this->syncQueueFactory->create();
  ...

Here, I want to declare syncQueueFactory of the model class QueueFactory

But if i give the same class in constructor naturally i get dependency error.

What is the alternate to use create()?

2
  • oh @Krishna, i just fixed that in my constructor, thought it was repeated ones as i had asked it the same very post since i dint get answer ! Commented Jul 25, 2016 at 7:09
  • I undeleted the post and replied the answer to the post @Krishna Commented Jul 25, 2016 at 7:16

2 Answers 2

1

You need to use an alias in your use statement:

use /Path/to/QueueFactory as QueueAlias

Then in your constructor you can do:

QueueAlias $syncQueueFactory
3
  • I am again getting the same error after alias name @Raphael, Circular dependency: Vendor\Module\Model\QueueFactory depends on Vendor\Module\Model\QueueFactory and vice versa. could you please check my file naming conventions here .magento.stackexchange.com/questions/126819/… Commented Jul 22, 2016 at 9:31
  • Have updated QueueFactory class, is my file naming conventions correct? Why data is not inserting in my custom table when i do any modifications to the product details? Commented Jul 22, 2016 at 9:34
  • Any update @Raphael Commented Jul 22, 2016 at 9:47
0

You should name your model class as Queue, not QueueFactory

7
  • I think im getting confused in the file naming conventions... can you please check my complete file structure...i have in this link magento.stackexchange.com/questions/126819/… Commented Jul 22, 2016 at 9:28
  • My model class name is Queue only though...but why am i not able to insert data as said in the above link Commented Jul 22, 2016 at 9:28
  • Any updated @kandy Commented Jul 22, 2016 at 9:47
  • If you add Factory suffix to any class, Magento generates factory class by self with "create" method. see devdocs.magento.com/guides/v2.0/extension-dev-guide/… for details Commented Jul 22, 2016 at 9:48
  • So no need to add this $this->_queue = $this->syncQueueFactory->create();? Commented Jul 22, 2016 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.