Skip to content

Resolving Circular Dependencies

Jason Jean edited this page Feb 28, 2020 · 2 revisions

Resolving Circular Dependencies

What are circular dependencies?

Circular dependencies occur when a providing project starts to depend somehow on a consumer of itself.

The simplest circular dependency involves 2 projects that depend on one another. But they can also involve more than 2 projects.

Why do circular dependencies occur?

There are several reasons why circular dependencies may arise.

Tightly knit logic in separate projects

A common case is that 2 separate projects contain tightly knit logic which frequently has to depend on each other. Usually, having granular projects is recommended. However, in this case, it may be more reasonable to collapse such projects into a single project that is free to depend on itself.

Extra logic in the consumer project

Another common case is that the consumer of a project has some extra logic that is desirable from producing libraries. When this extra logic is consumed by a producing project, it creates a circular dependency. The solution to this case is to separate the extra logic in the producing project into a new project that is shared between the projects which desire this logic:

Other reasons

There may be other reasons that have not been described here in this document or are not generalizable.

Glossary

A consuming project is a project that imports another project.

A providing project is a project that is imported by another project.