Search code examples
androiddependenciescycledagger

Easy way to check Dagger 2 dependency cycle?


Here.

So after bit of refactoring in my project I've ended up with the dependency cycle SOMEWHERE. My module with @Provided dependencies is huge and it's really hard to understand what exactly is the cause.

Here is console log: http://pastebin.com/yxDDEHgz

As you can see it's huge and doesn't tell me nothing. Is there any way to quickly check which dependency injection causes a cycle?


Solution

  • You just need to pay attention to the lines starting with [parameter: …

    if you attention you see your cycle is like below:

    line 16: [parameter: packagename.map.mapservice.IMapService mapService]
    
    line 13: [parameter: packagename.lib.common.IApplicationVisibility mapVisibility]
    
    line 9: [parameter: packagename.lib.notifications.INotificationSettings notificationSettings]
    
    line 7: [parameter: packagename.map.mapcontent.MarkerClickHandler markerClickHandler]
    
    line 5: [parameter: packagename.map.mapservice.IMapService mapService]
    

    and here you trying to re-inject IApplicationVisibility so cycle is here :

    line 3: [injected field of type: packagename.lib.common.IApplicationVisibility applicationVisibility]
    

    IMapService -> IApplicationVisibility -> INotificationSettings -> MarkerClickHandler -> IMapService (again IMapService !!!) -> IApplicationVisibility

    you injected IMapService again in MarkerClickHandler which starts the cycle !!