问题
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