public final class ContainerBuilder extends Object
Container
. The combination of
dependency type and name uniquely identifies a dependency mapping; you can
use the same name for two different types. Not safe for concurrent use.
Adds the following factories by default:
Modifier and Type | Class and Description |
---|---|
static interface |
ContainerBuilder.Command
Implemented by classes which participate in building a container.
|
Constructor and Description |
---|
ContainerBuilder()
Constructs a new builder.
|
Modifier and Type | Method and Description |
---|---|
<T> ContainerBuilder |
alias(Class<T> type,
String alias)
Convenience method. Equivalent to
alias(type, Container.DEFAULT_NAME,
type) . |
<T> ContainerBuilder |
alias(Class<T> type,
String name,
String alias)
Maps an existing factory to a new name.
|
ContainerBuilder |
constant(String name,
boolean value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
char value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
Class value)
Maps a class to the given name.
|
ContainerBuilder |
constant(String name,
double value)
Maps a constant value to the given name.
|
<E extends Enum<E>> |
constant(String name,
E value)
Maps an enum to the given name.
|
ContainerBuilder |
constant(String name,
float value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
int value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
long value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
short value)
Maps a constant value to the given name.
|
ContainerBuilder |
constant(String name,
String value)
Maps a constant value to the given name.
|
boolean |
contains(Class<?> type)
Convenience method. Equivalent to
contains(type,
Container.DEFAULT_NAME) . |
boolean |
contains(Class<?> type,
String name) |
Container |
create(boolean loadSingletons)
Creates a
Container instance. |
<T> ContainerBuilder |
factory(Class<T> type)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, type) . |
<T> ContainerBuilder |
factory(Class<T> type,
Class<? extends T> implementation)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, implementation) . |
<T> ContainerBuilder |
factory(Class<T> type,
Class<? extends T> implementation,
Scope scope)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, implementation, scope) . |
<T> ContainerBuilder |
factory(Class<T> type,
Factory<? extends T> factory)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, factory, Scope.PROTOTYPE) . |
<T> ContainerBuilder |
factory(Class<T> type,
Factory<? extends T> factory,
Scope scope)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, factory, scope) . |
<T> ContainerBuilder |
factory(Class<T> type,
Scope scope)
Convenience method. Equivalent to
factory(type,
Container.DEFAULT_NAME, type, scope) . |
<T> ContainerBuilder |
factory(Class<T> type,
String name)
Convenience method. Equivalent to
factory(type, name, type) . |
<T> ContainerBuilder |
factory(Class<T> type,
String name,
Class<? extends T> implementation)
Maps an implementation class to a given dependency type and name.
|
<T> ContainerBuilder |
factory(Class<T> type,
String name,
Class<? extends T> implementation,
Scope scope)
Maps an implementation class to a given dependency type and name.
|
<T> ContainerBuilder |
factory(Class<T> type,
String name,
Factory<? extends T> factory)
Convenience method. Equivalent to
factory(type, name, factory,
Scope.PROTOTYPE) . |
<T> ContainerBuilder |
factory(Class<T> type,
String name,
Factory<? extends T> factory,
Scope scope)
Maps a factory to a given dependency type and name.
|
<T> ContainerBuilder |
factory(Class<T> type,
String name,
Scope scope)
Convenience method. Equivalent to
factory(type, name, type,
scope) . |
ContainerBuilder |
injectStatics(Class<?>... types)
Upon creation, the
Container will inject static fields and methods
into the given classes. |
void |
setAllowDuplicates(boolean val) |
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory, Scope scope)
T
- typetype
- of dependencyname
- of dependencyfactory
- creates objects to injectscope
- scope of injected instancespublic <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory, Scope scope)
factory(type,
Container.DEFAULT_NAME, factory, scope)
.T
- typetype
- of dependencyfactory
- of dependencyscope
- scope of injected instancesfactory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory)
factory(type, name, factory,
Scope.PROTOTYPE)
.T
- typetype
- of dependencyname
- of dependencyfactory
- of dependencyfactory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory)
factory(type,
Container.DEFAULT_NAME, factory, Scope.PROTOTYPE)
.T
- typetype
- of dependencyfactory
- of dependencyfactory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Class<? extends T> implementation, Scope scope)
T
- typetype
- of dependencyname
- of dependencyimplementation
- classscope
- scope of injected instancespublic <T> ContainerBuilder factory(Class<T> type, String name, Class<? extends T> implementation)
Maps an implementation class to a given dependency type and name. Creates instances using the container, recursively injecting dependencies.
Sets scope to value from Scoped
annotation on the
implementation class. Defaults to Scope.PROTOTYPE
if no annotation
is found.
T
- typetype
- of dependencyname
- of dependencyimplementation
- classpublic <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation)
factory(type,
Container.DEFAULT_NAME, implementation)
.T
- typetype
- of dependencyimplementation
- classfactory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type)
factory(type,
Container.DEFAULT_NAME, type)
.T
- typetype
- of dependencyfactory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type, String name)
factory(type, name, type)
.T
- typetype
- of dependencyname
- of dependencyfactory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation, Scope scope)
factory(type,
Container.DEFAULT_NAME, implementation, scope)
.T
- typetype
- of dependencyimplementation
- classscope
- the scopefactory(Class, String, Class, Scope)
public <T> ContainerBuilder factory(Class<T> type, Scope scope)
factory(type,
Container.DEFAULT_NAME, type, scope)
.T
- typetype
- of dependencyscope
- the scopefactory(Class, String, Class, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Scope scope)
factory(type, name, type,
scope)
.T
- typetype
- of dependencyname
- of dependencyscope
- the scopefactory(Class, String, Class, Scope)
public <T> ContainerBuilder alias(Class<T> type, String alias)
alias(type, Container.DEFAULT_NAME,
type)
.T
- typetype
- of dependencyalias
- of dependencyalias(Class, String, String)
public <T> ContainerBuilder alias(Class<T> type, String name, String alias)
T
- typetype
- of dependencyname
- of dependencyalias
- of to the dependencypublic ContainerBuilder constant(String name, String value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, int value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, long value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, boolean value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, double value)
name
- namevalue
- constant valuepublic ContainerBuilder constant(String name, float value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, short value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, char value)
name
- namevalue
- valuepublic ContainerBuilder constant(String name, Class value)
name
- namevalue
- valuepublic <E extends Enum<E>> ContainerBuilder constant(String name, E value)
E
- value typename
- namevalue
- valuepublic ContainerBuilder injectStatics(Class<?>... types)
Container
will inject static fields and methods
into the given classes.types
- for which static members will be injectedpublic boolean contains(Class<?> type, String name)
type
- type of classname
- name of classpublic boolean contains(Class<?> type)
contains(type,
Container.DEFAULT_NAME)
.type
- type of classpublic Container create(boolean loadSingletons)
Container
instance. Injects static members for classes
which were registered using injectStatics(Class...)
.loadSingletons
- If true, the container will load all singletons
now. If false, the container will lazily load singletons. Eager loading
is appropriate for production use while lazy loading can speed
development.IllegalStateException
- if called more than oncepublic void setAllowDuplicates(boolean val)
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.