|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.inject.InjectorBuilder
public class InjectorBuilder
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();
}
}
| Constructor Summary | |
|---|---|
InjectorBuilder()
|
|
| Method Summary | |
|---|---|
InjectorBuilder |
addModules(Iterable<? extends Module> modules)
Adds more modules that will be used when the Injector is created. |
InjectorBuilder |
addModules(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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public InjectorBuilder()
| Method Detail |
|---|
public InjectorBuilder stage(Stage stage)
Stage.PRODUCTION,
singletons will be eagerly loaded when the Injector is built.
public InjectorBuilder requireExplicitBindings()
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
Binding.getProvider() cannot be used.
By default, explicit bindings are not required.
public InjectorBuilder disableCircularProxies()
Proxy when a circular dependency
is found.
public InjectorBuilder addModules(Iterable<? extends Module> modules)
public InjectorBuilder addModules(Module... modules)
public Injector build()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||