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
18
votes
1 answer

Python mutually dependent classes (circular dependencies)

I've searched a lot, but what I find is mainly examples of recursive programming in python. So here goes the question: How can I achieve this? class A: b = B() class B: a = A()
francescortiz
  • 531
  • 4
  • 13
17
votes
3 answers

Static Circular Dependency in Java

for the following code: class A { public static int X; static { X = B.Y + 1;} } public class B { public static int Y = A.X + 1; static {} public static void main(String[] args) { System.out.println("X = "+A.X+", Y =…
topgun_ivard
  • 8,376
  • 10
  • 38
  • 45
17
votes
4 answers

FastAPI / Pydantic circular references in separate files

I would love to use a schema that looks something like the following in FastAPI: from __future__ import annotations from typing import List from pydantic import BaseModel class Project(BaseModel): members: List[User] class User(BaseModel): …
Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40
17
votes
1 answer

SQLAlchemy circular dependency - how to solve it?

I have two tables, News and Files: # unrelated columns removed class News(db.Model): id = db.Column(db.Integer, primary_key=True) file_id_logo = db.Column(db.Integer, db.ForeignKey('files.id')) logo = db.relationship('File',…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
17
votes
1 answer

How does browserify handle circular dependencies?

I'm considering moving a large browser-based code base over to CommonJS (it's an AngularJS 1.x application written in TypeScript). The application has circular dependencies, so I think RequireJS is out of the question. How does Browserify handle…
Eric
  • 5,842
  • 7
  • 42
  • 71
17
votes
2 answers

How does compiling circular dependencies work?

I've made the example in Java but I think (not tested) that it works in other (all?) languages. You have 2 files. First, M.java: public class MType { XType x; MType() {x = null;} } Second, another file (in the same directory),…
Fabio Filippi
  • 1,732
  • 25
  • 40
17
votes
3 answers

In C#, how to find chain of circular dependency?

This error usually occurs when one deployment project contains the project outputs of a second deployment project, and the second project contains the outputs of the first project. I have a method that check circular dependency. In input, we have a…
Anatoly
  • 1,908
  • 4
  • 25
  • 47
17
votes
3 answers

Injecting $http into angular factory($exceptionHandler) results in a Circular dependency

When I try inject $http into an overridden factory I get the error: Uncaught Error: [$injector:cdep] Circular dependency found: $http <- $exceptionHandler <- $rootScope AngularModule.factory('$exceptionHandler', function ($http) { any ideas…
FutuToad
  • 2,750
  • 5
  • 36
  • 63
16
votes
2 answers

Nestjs Circular dependency forwardRef() drawbacks

Official Circular dependency says: A circular dependency occurs when two classes depend on each other. For example, class A needs class B, and class B also needs class A. Circular dependencies can arise in Nest between modules and between…
Jasurbek Nabijonov
  • 1,607
  • 3
  • 24
  • 37
16
votes
2 answers

Webpack ES6 modules circular dependencies when using index files

I have a big project, I try to refactor to ES6 modules right now. To make further development easier, I wanted to introduce index files, which just export all modules within the directory: index.js: export { default as ModuleA } from…
tjwelde
  • 353
  • 1
  • 2
  • 9
16
votes
3 answers

How to avoid circular dependency caused by type hinting of pointer attributes in python

Consider the two modules (in the same folder): firstly, person.py from typing import List from .pet import Pet class Person: def __init__(self, name: str): self.name = name self.pets: List[Pet] = [] def…
16
votes
2 answers

Is everything after an exporting namespace not exported?

I was reading about modules, and I wished to do something like this: a.cpp module foo.a; export namespace foo { struct A { void doA(); }; } import foo.b; void foo::A::doA() { B{}.doB(); } b.cpp module foo.b; export namespace…
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
16
votes
10 answers

circular dependencies between dlls with visual studio

I have a circular dependency between two functions. I would like each of these functions to reside in its own dll. Is it possible to build this with visual studio? foo(int i) { if (i > 0) bar(i -i); } -> should compile into foo.dll bar(int…
Kris Steegmans
  • 161
  • 1
  • 2
  • 4
16
votes
5 answers

Is it possible to enable circular dependencies in Visual Studio at the assembly level? Would mutually dependent assemblies even be possible?

This probably sounds like a stupid question, but I'm going to give it a shot anyway. So in Visual Studio, you can't have two projects X and Y such that X references Y and Y references X. In general, I can totally understand how having a circular…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
16
votes
3 answers

Exception to the Rule of Three?

I've read a lot about the C++ Rule of Three. Many people swear by it. But when the rule is stated, it almost always includes a word like "usually," "likely," or "probably," indicating that there are exceptions. I haven't seen much discussion of what…
Sam Kauffman
  • 1,221
  • 11
  • 30