{"id":378573,"date":"2023-05-01T07:00:44","date_gmt":"2023-05-01T07:00:44","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=378573"},"modified":"2023-07-20T09:14:40","modified_gmt":"2023-07-20T09:14:40","slug":"what-is-a-circular-dependency","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/","title":{"rendered":"What is a circular dependency?"},"content":{"rendered":"\n<p>Circular dependency is when class &#8220;A&#8221; depends on class &#8220;B&#8221;  to use their property for any requirement and the same class &#8220;B&#8221; depends on class &#8220;A&#8221; for some dependency in Project. This means to compile Project A you must first compile Project B, but you can&#8217;t do that as B requires A to be compiled. This is the problem that circular dependencies cause.<\/p>\n\n\n\n<p>Example:-<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\">class A {\n    public $b;\n\n    public function __construct(B $b) {\n        $this-&gt;b = $b;\n    }\n}\n\nclass B {\n    public $a;\n\n    public function __construct(A $a) {\n        $this-&gt;a = $a;\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Error:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\">Circular dependency: Magento\\Store\\Model\\ResourceModel\\Config\\Collection\\Scoped depends on Magento\\Store\\Model\\ResourceModel\\Config\\Collection\\Scoped and vice versa.<\/pre>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"530\" height=\"277\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\" alt=\"circular dependency\" class=\"wp-image-378799\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg 530w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_-300x157.jpg 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_-250x131.jpg 250w\" sizes=\"(max-width: 530px) 100vw, 530px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to Resolve Circular Dependency?<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>To fix the problem. Create a third class &#8220;C,&#8221; which contains the classes that both A and B depend on. So they no longer depend on each other.<\/li>\n\n\n\n<li>Combine class &#8220;A&#8221; and class &#8220;B&#8221; so you don&#8217;t need to depend on other classes if both classes code combine.<\/li>\n<\/ol>\n\n\n\n<p>What is <a href=\"https:\/\/devdocs.magento.com\/guides\/v2.3\/extension-dev-guide\/depend-inj.html\">dependency injection<\/a> in Magento 2?<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Circular dependency is when class &#8220;A&#8221; depends on class &#8220;B&#8221; to use their property for any requirement and the same class &#8220;B&#8221; depends on class &#8220;A&#8221; for some dependency in Project. This means to compile Project A you must first compile Project B, but you can&#8217;t do that as B requires A to be compiled. <a href=\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":497,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13,1],"tags":[],"class_list":["post-378573","post","type-post","status-publish","format-standard","hentry","category-magento","category-php","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is a circular dependency? - Webkul Blog<\/title>\n<meta name=\"description\" content=\"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is a circular dependency? - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:author\" content=\"pammu23\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-01T07:00:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-20T09:14:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\" \/>\n<meta name=\"author\" content=\"Pramod Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pramod Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\"},\"author\":{\"name\":\"Pramod Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590\"},\"headline\":\"What is a circular dependency?\",\"datePublished\":\"2023-05-01T07:00:44+00:00\",\"dateModified\":\"2023-07-20T09:14:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\"},\"wordCount\":130,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\",\"articleSection\":[\"magento\",\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\",\"url\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\",\"name\":\"What is a circular dependency? - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\",\"datePublished\":\"2023-05-01T07:00:44+00:00\",\"dateModified\":\"2023-07-20T09:14:40+00:00\",\"description\":\"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg\",\"width\":530,\"height\":277,\"caption\":\"frame_1__2_\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is a circular dependency?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590\",\"name\":\"Pramod Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Pramod Kumar\"},\"description\":\"Software Engineer\",\"sameAs\":[\"pammu23\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/pramodkumar-mg592\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is a circular dependency? - Webkul Blog","description":"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/","og_locale":"en_US","og_type":"article","og_title":"What is a circular dependency? - Webkul Blog","og_description":"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP","og_url":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_author":"pammu23","article_published_time":"2023-05-01T07:00:44+00:00","article_modified_time":"2023-07-20T09:14:40+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg","type":"","width":"","height":""}],"author":"Pramod Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Pramod Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/"},"author":{"name":"Pramod Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590"},"headline":"What is a circular dependency?","datePublished":"2023-05-01T07:00:44+00:00","dateModified":"2023-07-20T09:14:40+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/"},"wordCount":130,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg","articleSection":["magento","php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/","url":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/","name":"What is a circular dependency? - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg","datePublished":"2023-05-01T07:00:44+00:00","dateModified":"2023-07-20T09:14:40+00:00","description":"What is a circular dependency, how to fix circular dependency, what is dependency injection, what is a design pattern in PHP","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/04\/frame_1__2_.jpg","width":530,"height":277,"caption":"frame_1__2_"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/what-is-a-circular-dependency\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is a circular dependency?"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590","name":"Pramod Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Pramod Kumar"},"description":"Software Engineer","sameAs":["pammu23"],"url":"https:\/\/webkul.com\/blog\/author\/pramodkumar-mg592\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/378573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/497"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=378573"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/378573\/revisions"}],"predecessor-version":[{"id":391980,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/378573\/revisions\/391980"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=378573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=378573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=378573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}