|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.inject.spi.SourceConsumer
com.google.inject.ContainerBuilder
public final class ContainerBuilder
Builds a dependency injection Container
. Binds Key
s to
implementations.
Creates several bindings by default:
Factory<T>
for each binding of type T
Container
iself
Logger
for the class being injected
Stage
passed to the builder's constructor
Nested Class Summary | |
---|---|
class |
ContainerBuilder.BindingBuilder<T>
Binds a Key to an implementation in a given scope. |
class |
ContainerBuilder.ConstantBindingBuilder
Builds a constant binding. |
class |
ContainerBuilder.LinkedBindingBuilder<T>
Links one binding to another. |
Constructor Summary | |
---|---|
ContainerBuilder()
Constructs a new builder for a development environment (see Stage.DEVELOPMENT ). |
|
ContainerBuilder(Stage stage)
Constructs a new builder. |
Method Summary | ||
---|---|---|
|
bind(Class<T> clazz)
Binds the given type. |
|
|
bind(Key<T> key)
Binds the given key. |
|
|
bind(TypeLiteral<T> typeLiteral)
Binds the given type. |
|
ContainerBuilder.ConstantBindingBuilder |
bindConstant(Annotation annotation)
Binds a constant to the given annotation. |
|
ContainerBuilder.ConstantBindingBuilder |
bindConstant(Class<? extends Annotation> annotationType)
Binds a constant to the given annotation type. |
|
Container |
create()
Creates a Container instance. |
|
void |
install(Module module)
Applies the given module to this builder. |
|
void |
intercept(Matcher<? super Class<?>> classMatcher,
Matcher<? super Method> methodMatcher,
MethodInterceptor... interceptors)
Applies the given method interceptor to the methods matched by the class and method matchers. |
|
|
link(Key<T> key)
Links the given key to another key effectively creating an alias for a binding. |
|
void |
requestStaticInjection(Class<?>... types)
Upon successful creation, the Container will inject static fields
and methods in the given classes. |
|
void |
scope(Class<? extends Annotation> annotationType,
Scope scope)
Adds a new scope. |
Methods inherited from class com.google.inject.spi.SourceConsumer |
---|
getSourceProvider, setSourceProvider, source, withSourceProvider |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ContainerBuilder(Stage stage)
stage
- we're running in. If the stage is Stage.PRODUCTION
,
we will eagerly load container-scoped objects.public ContainerBuilder()
Stage.DEVELOPMENT
).
Method Detail |
---|
public void intercept(Matcher<? super Class<?>> classMatcher, Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors)
classMatcher
- matches classes the interceptor should apply to. For
example: only(Runnable.class)
.methodMatcher
- matches methods the interceptor should apply to. For
example: annotatedWith(Transactional.class)
.interceptors
- to applypublic void scope(Class<? extends Annotation> annotationType, Scope scope)
Scope
instance to a given annotation.
public <T> ContainerBuilder.BindingBuilder<T> bind(Key<T> key)
public <T> ContainerBuilder.BindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
public <T> ContainerBuilder.BindingBuilder<T> bind(Class<T> clazz)
public <T> ContainerBuilder.LinkedBindingBuilder<T> link(Key<T> key)
public ContainerBuilder.ConstantBindingBuilder bindConstant(Annotation annotation)
public ContainerBuilder.ConstantBindingBuilder bindConstant(Class<? extends Annotation> annotationType)
public void requestStaticInjection(Class<?>... types)
Container
will inject static fields
and methods in the given classes.
types
- for which static members will be injectedpublic void install(Module module)
public Container create() throws ContainerCreationException
Container
instance. Injects static members for classes
which were registered using requestStaticInjection(Class...)
.
ContainerCreationException
- if configuration errors are found. The
expectation is that the application will log this exception and exit.
IllegalStateException
- if called more than once
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |