needle
needle copied to clipboard
How to resolve dependency cycle?
I am going through migrating a legacy codebase onto using Needle and encountered circular dependencies. Some of my scopes have children scopes that in turn declare one of the great great parent components as their dependency, hence the dependency cycle.
The scenario I'm dealing with isn't necessarily an error - the UI I have is for users browsing through folders which means the user can open one folder and then another subfolder and then another infinitively showing the same UI/component as a child of the previous one. Think dropbox file browsing.
The issue I'm experiencing won't be a problem at runtime but since Needle is trying to resolve the dependency tree before compile time so that it can be deterministic and correct at compile time it can't really process it.
How can this be resolved? Some sort of a "break" at some point with BootstrapComponent
creating a second parallel dependency tree for the part of the app I want to circularly depend on?
Also, if I get an output like this from a needle call LocationContextMenuListComponent->LocationDetailTabsViewControllerComponent->WorkOrderDetailsLocationSectionComponent->WorkOrderDetailsViewModelComponent->WorkOrderDependencyContainerComponent->WorkOrderDetailsCoordinatorComponent->WorkOrdersListViewControllerComponent->BookmarkedWorkOrdersContainerViewControllerComponent->OfflineTableSourceComponent->LocationContextMenuListComponent
how would I go about reading and resolving it?
I've run into the same problem, though for me the cycle is even shorter. I am developing an app for viewing images on image boards. An image's page contains links to other images. This means that logically PostDetailComponent
can create and become a parent of another PostDetailComponent
, which makes sense and does indeed create a cycle.
Cycles such as this are common and I remember a time when Needle did not complain about them. This seems to have changed in the past couple of versions.
@rudro your comments on the subject would be greatly appreciated.