简体   繁体   English

检查Dagger 2依赖周期的简单方法?

[英]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. 因此,在我的项目中进行了一些重构之后,我最终遇到了依赖循环SOMEWHERE。 My module with @Provided dependencies is huge and it's really hard to understand what exactly is the cause. 我的具有@Provided依赖项的模块非常庞大,很难理解到底是什么原因。

Here is console log: http://pastebin.com/yxDDEHgz 这是控制台日志: 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: … 您只需要注意以[parameter: …开头的行[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 : 在这里,您尝试重新注入IApplicationVisibility因此循环在这里:

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

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

you injected IMapService again in MarkerClickHandler which starts the cycle !! 您再次将IMapService注入了MarkerClickHandler ,从而开始了循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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