User's Guide

Bindings

qianmoQqianmoQ· 更新于 2026-09-23· 阅读 4 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Bindings

Overview of bindings in Guice

A binding is an object that corresponds to an entry in the Guice map. You add new entries into the Guice map by creating bindings.

Creating Bindings

To create bindings, extend AbstractModule and override its configure method. In the method body, call bind() to specify each binding. These methods are type checked so the compiler can report errors if you use the wrong types. Once you've created your modules, pass them as arguments to Guice.createInjector() to build an injector, which can then be used to bootstrap your application.

Use modules to create linked bindings, instance bindings, @Provides methods, provider bindings, constructor bindings and untargetted bindings.

More Bindings

In addition to the bindings you specify the injector includes built-in bindings. When a dependency is requested but not found it attempts to create a just-in-time binding. The injector also includes bindings for the providers of its other bindings.

评论

登录后参与评论

正在加载评论…