开发者

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

开发者 https://www.devze.com 2023-04-04 08:03 出处:网络
I was wonder, why do开发者_JAVA技巧 we need to provide bindings explicitly sometimes and not other times in the module?

I was wonder, why do开发者_JAVA技巧 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消