Circular dependencies
Less than to read
Circular dependencies between packages occur when two or more packages depend on each other in a loop. This creates a cycle and can lead to various issues in development and is rejected by the code generator.
To address circular dependencies:
- Refactor the code structure: Consider refactoring your code to break the circular dependency. This might involve reorganizing the code into different packages or redefining the dependencies between them.
- High level packages should not depend on low level packages.
- Identify common functionalities causing the circular dependency and extract them into a separate package that both dependent components can reference without creating a loop. Creating linking or shared packages can help break the direct dependency chain.
- Break down large packages into smaller, more focused ones.
Circular dependencies are detected by the code generator that will raise an error. An example:
To identify entities at the origin of a circular dependency, you can run the APACKCYC SQL query in the GESALQ function.
On the example presented in the image above, a circular dependency is detected:
- The local menu purchaseType in the SupplierInvoiceHeader node leads to the creation of a dependency on the x3-finance-package in the x3-invoicing-data.
- The tax property leads to the creation of a dependency on the x3-invoicing-data in the x3-finance-package.
To resolve this dependency, a solution can be to move the local menu purchaseType into the x3-invoicing-data package by creating an enum exception in the GESAENUMB function.
Note: The APACKCYC query can only detect a loop in a mono level dependency chain but not in a multi-level one.