public final class

InjectorBuilder

extends Object
java.lang.Object
   ↳ com.google.inject.InjectorBuilder

Class Overview

The advanced entry point to the Guice framework. Creates Injectors from Modules, allowing many options to be configured for the Injector.

Guice supports a model of development that draws clear boundaries between APIs, Implementations of these APIs, Modules which configure these implementations, and finally Applications which consist of a collection of Modules. It is the Application, which typically defines your main() method, that bootstraps the Guice Injector using the Guice class, as in this example:

     public class FooApplication {
       public static void main(String[] args) {
         Injector injector = new InjectorBuilder().
             .stage(Stage.PRODUCTION)
             . . . 
             .addModules(
                new ModuleA(),
                new ModuleB(),
                . . .
                new FooApplicationFlagsModule(args)
             )
             .build();
         );

         // Now just bootstrap the application and you're done
         FooStarter starter = injector.getInstance(FooStarter.class);
         starter.runApplication();
       }
     }
 

Summary

Public Constructors
InjectorBuilder()
Public Methods
InjectorBuilder addModules(Module... modules)
Adds more modules that will be used when the Injector is created.
InjectorBuilder addModules(Iterable<? extends Module> modules)
Adds more modules that will be used when the Injector is created.
Injector build()
Builds the injector.
InjectorBuilder disableCircularProxies()
Prevents Guice from constructing a Proxy when a circular dependency is found.
InjectorBuilder requireExplicitBindings()
If explicit bindings are required, then classes that are not explicitly bound in a module cannot be injected.
InjectorBuilder stage(Stage stage)
Sets the stage for the injector.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public InjectorBuilder ()

Public Methods

public InjectorBuilder addModules (Module... modules)

Adds more modules that will be used when the Injector is created.

public InjectorBuilder addModules (Iterable<? extends Module> modules)

Adds more modules that will be used when the Injector is created.

public Injector build ()

Builds the injector.

public InjectorBuilder disableCircularProxies ()

Prevents Guice from constructing a Proxy when a circular dependency is found.

public InjectorBuilder requireExplicitBindings ()

If explicit bindings are required, then classes that are not explicitly bound in a module cannot be injected. Bindings created through a linked binding (bind(Foo.class).to(FooImpl.class)) are allowed, but the implicit binding (FooImpl) cannot be directly injected unless it is also explicitly bound. Tools can still retrieve bindings for implicit bindings (bindings created through a linked binding) if explicit bindings are required, however getProvider() cannot be used. By default, explicit bindings are not required.

public InjectorBuilder stage (Stage stage)

Sets the stage for the injector. If the stage is PRODUCTION, singletons will be eagerly loaded when the Injector is built.