Questions tagged [circular-dependency]

circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly.

1693 questions
10
votes
4 answers

Remove python circular import

user.py: from story import Story class User: ... def get_stories(self): story_ids = [select from database] return [Story.get_by_id(id) for id in story_ids] story.py from user import User class Story: ... def…
wong2
  • 34,358
  • 48
  • 134
  • 179
10
votes
3 answers

Android Gradle build and circular dependency

I have an Android project in IntelliJ IDEA. It consists of two modules: app and library. App depends on library and library depends on app (Yes, it's not good, but I have what I have and can't change this). IDEA in project settings warn me about…
10
votes
1 answer

Detecting the cause of a circular dependency in Unity

Is it possible to configure Unity to either detect a circular reference or to intercept the type resolver to display some debugging information? Example Here are a couple of interfaces and classes which are dependent upon each other public…
10
votes
2 answers

Spring circular dependency using setters

I have read that to avoid circular dependencies I can use @Autowired on setters instead of constructors. If so, why does this fail? @Component private static class A { @Autowired public A(B b) { } } @Component private static class B { …
Adam Pierzchała
  • 2,244
  • 4
  • 30
  • 32
10
votes
7 answers

Database Design: Circular dependency

Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products' have fields id, name and company_id. A company must have a flagship product (1:1 relationship) and all products have one company (1:N…
LiraNuna
  • 64,916
  • 15
  • 117
  • 140
10
votes
4 answers

C++ circular header includes

I know that similar questions to this have been asked before but after doing my research I still have questions about circular header includes. //FooA.h #ifndef H_FOOA #define H_FOOA #include "foob.h" class FooA{ public: FooB…
user1600812
  • 359
  • 1
  • 2
  • 11
10
votes
2 answers

PostgreSQL design of dependency tree without circular dependencies

I have a table, call it EVENTS, where each row can depend on 0 or more other rows in the table. I need a way of representing this relationship that also prevents circular dependencies (i.e. a group of events leading back into an event in that same…
Adam
  • 3,668
  • 6
  • 30
  • 55
9
votes
2 answers

Are circular dependencies considered bad design?

In my work (which is 90% Java but I'm sure this question applies to other languages) I often create two classes that "know about" each other. More concretely, class A imports B, and class B imports class A, and both have member or local variables…
John Fitzpatrick
  • 4,207
  • 7
  • 48
  • 71
9
votes
2 answers

Can I avoid a dependency cycle with one edge being a test dependency?

Consider a testCycle parent with modules DummyCore and TestFramework. TestFramework depends on DummyCore, and DummyCore has a test dedepency on TestFramework. Building and testing each module independently maven has no problems. But mvn test the…
simpatico
  • 10,709
  • 20
  • 81
  • 126
9
votes
2 answers

How to implement dependency injection in Startup.cs when dependencies are circular?

I have a MyProject project where I have IMyService interface and MyService class that implements IMyService. In Startup.cs class I dependency injection them: // MyProject project | Startup.cs public void ConfigureServices(IServiceCollection…
Lassi Autio
  • 1,147
  • 1
  • 13
  • 35
9
votes
2 answers

Angular Circular Module import

I have two Modules with components which use each other. So I have to import "word" in "test" and "test" in "word" --> throw an error... How can I do ? Module "test": @NgModule({ declarations: [ AppTest1Component, …
MatDepInfo
  • 317
  • 3
  • 16
9
votes
3 answers

Circular reference and constructors

I'm trying to build an Attribute that validates a certain instance of a type. In order to do this I have to cast the ObjectInstance to that type. And I need to set the attribute on the member of that type. So we need to resort to the and keyword…
Anemoia
  • 7,928
  • 7
  • 46
  • 71
9
votes
1 answer

Why do all of the leading open-source Java libraries have circular dependencies among their packages?

I've been researching Java package structure and dependency patterns over the last few weeks. One of the common threads across the writings on the subject is the simple rule that package dependencies should form a directed acyclic graph (DAG). …
Elliot
  • 189
  • 8
9
votes
3 answers

Circular dependencies in StructureMap - can they be broken with property injection?

I've got the simplest kind of circular dependency in structuremap - class A relies on class B in its constructor, and class B relies on class A in its constructor. To break the dependency, I made class B take class A as a property, rather than a…
Andy
  • 3,596
  • 8
  • 34
  • 33
9
votes
1 answer

Resolving circular dependencies with Node.js require and classes in CoffeeScript

I want to know if there is a way to idiomatically avoid issues with circular dependencies with Node.js's require while using CoffeeScript classes and super. Given the following simplified CoffeeScript files: a.coffee: C = require './c' B = require…