简体   繁体   中英

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?

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 !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM