|
|||||||||
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. A binding implementation could be anything from a constant
value to an object in the HTTP session.
Not safe for concurrent use.
Default bindings include:
Factory<T>
for each binding of type T
Container
iself
Logger
for the class being injected
Converts constants as needed from String
to any primitive type
in addition to enum
and Class<?>
.
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. |
|
ContainerBuilder(ConstructionProxyFactory constructionProxyFactory)
Constructs a new builder. |
Method Summary | ||
---|---|---|
void |
apply(Module module)
Applies the given module to this builder. |
|
|
bind(java.lang.Class<T> clazz)
Binds the given type. |
|
|
bind(Key<T> key)
Binds the given key. |
|
ContainerBuilder.ConstantBindingBuilder |
bind(java.lang.String name)
Binds a constant to the given name. |
|
|
bind(TypeLiteral<T> typeLiteral)
Binds the given type. |
|
void |
bindProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Binds a string constant for each property. |
|
void |
bindProperties(java.util.Properties properties)
Binds a string constant for each property. |
|
Container |
create(boolean preload)
Creates a Container instance. |
|
|
link(Key<T> key)
Links the given key to another key effectively creating an alias for a binding. |
|
void |
put(java.lang.String name,
Scope scope)
Maps a Scope instance to a given scope name. |
|
void |
requestStaticInjection(java.lang.Class<?>... types)
Upon successful creation, the Container will inject static fields
and methods in the given classes. |
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(ConstructionProxyFactory constructionProxyFactory)
constructionProxyFactory
- to use when constructing objectspublic ContainerBuilder()
Method Detail |
---|
public void put(java.lang.String name, Scope scope)
Scope
instance to a given scope name. Scopes should be
mapped before used in bindings. @Scoped.value()
references this
name.
public <T> ContainerBuilder.BindingBuilder<T> bind(Key<T> key)
public <T> ContainerBuilder.BindingBuilder<T> bind(TypeLiteral<T> typeLiteral)
public <T> ContainerBuilder.BindingBuilder<T> bind(java.lang.Class<T> clazz)
public <T> ContainerBuilder.LinkedBindingBuilder<T> link(Key<T> key)
public ContainerBuilder.ConstantBindingBuilder bind(java.lang.String name)
public void bindProperties(java.util.Map<java.lang.String,java.lang.String> properties)
public void bindProperties(java.util.Properties properties)
public void requestStaticInjection(java.lang.Class<?>... types)
Container
will inject static fields
and methods in the given classes.
types
- for which static members will be injectedpublic void apply(Module module)
public Container create(boolean preload) throws ContainerCreationException
Container
instance. Injects static members for classes
which were registered using requestStaticInjection(Class...)
.
preload
- If true, the container will load all container-scoped
bindings now. If false, the container will lazily load them. Eager
loading is appropriate for production use (catch errors early and take
any performance hit up front) while lazy loading can speed development.
ContainerCreationException
- if configuration errors are found. The
expectation is that the application will log this exception and exit.
java.lang.IllegalStateException
- if called more than once
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |