When to provide explicit binding and when to leverage the automatic binding on Guice

家住魔仙堡 提交于 2019-12-11 03:15:13

问题


I was wonder, why do we need to provide bindings explicitly sometimes and not other times in the module? How does Guice decide when we need the binding and when not?

Is it because if a dependency has no multiple implementations and it is injected elsewhere as a dependencies it will be automatically bound as part of a dependency graph?

Thanks


回答1:


You need a binding (either through a bind, an @Provides method or an @ImplementedBy annotation) for anything you want injected that is not a concrete class with a no-arg constructor or an @Inject annotated constructor.



来源:https://stackoverflow.com/questions/7364976/when-to-provide-explicit-binding-and-when-to-leverage-the-automatic-binding-on-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!