Package org.apache.struts2.inject
Class ContainerBuilder
java.lang.Object
org.apache.struts2.inject.ContainerBuilder
Builds a dependency injection
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:
- Author:
- crazybob@google.com (Bob Lee)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplemented by classes which participate in building a container. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> ContainerBuilderConvenience method. Equivalent toalias(type, Container.DEFAULT_NAME, type).<T> ContainerBuilderMaps an existing factory to a new name.Maps a constant value to the given name.Maps a constant value to the given name.Maps a constant value to the given name.Maps a constant value to the given name.Maps a constant value to the given name.Maps a constant value to the given name.Maps a constant value to the given name.<E extends Enum<E>>
ContainerBuilderMaps an enum to the given name.Maps a class to the given name.Maps a constant value to the given name.booleanConvenience method. Equivalent tocontains(type, Container.DEFAULT_NAME).booleancreate(boolean loadSingletons) Creates aContainerinstance.<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, type).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, implementation).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, implementation, scope).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, name, type).<T> ContainerBuilderMaps an implementation class to a given dependency type and name.<T> ContainerBuilderMaps an implementation class to a given dependency type and name.<T> ContainerBuilderConvenience method. Equivalent tofactory(type, name, factory, Scope.PROTOTYPE).<T> ContainerBuilderMaps a factory to a given dependency type and name.<T> ContainerBuilderConvenience method. Equivalent tofactory(type, name, type, scope).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, factory, Scope.PROTOTYPE).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, factory, scope).<T> ContainerBuilderConvenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, type, scope).injectStatics(Class<?>... types) Upon creation, theContainerwill inject static fields and methods into the given classes.voidsetAllowDuplicates(boolean val)
-
Constructor Details
-
ContainerBuilder
public ContainerBuilder()Constructs a new builder.
-
-
Method Details
-
factory
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory, Scope scope) Maps a factory to a given dependency type and name.- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyfactory- creates objects to injectscope- scope of injected instances- Returns:
- this builder
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, factory, scope).- Type Parameters:
T- type- Parameters:
type- of dependencyfactory- of dependencyscope- scope of injected instances- Returns:
- a container builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, name, factory, Scope.PROTOTYPE).- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyfactory- of dependency- Returns:
- a container builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, factory, Scope.PROTOTYPE).- Type Parameters:
T- type- Parameters:
type- of dependencyfactory- of dependency- Returns:
- a container builder
- See Also:
-
factory
public <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. Creates instances using the container, recursively injecting dependencies.- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyimplementation- classscope- scope of injected instances- Returns:
- this builder
-
factory
Maps an implementation class to a given dependency type and name. Creates instances using the container, recursively injecting dependencies.
Sets scope to value from
Scopedannotation on the implementation class. Defaults toScope.PROTOTYPEif no annotation is found.- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyimplementation- class- Returns:
- this builder
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, implementation).- Type Parameters:
T- type- Parameters:
type- of dependencyimplementation- class- Returns:
- this builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, type).- Type Parameters:
T- type- Parameters:
type- of dependency- Returns:
- this builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, name, type).- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependency- Returns:
- this builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, implementation, scope).- Type Parameters:
T- type- Parameters:
type- of dependencyimplementation- classscope- the scope- Returns:
- this builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, Container.DEFAULT_NAME, type, scope).- Type Parameters:
T- type- Parameters:
type- of dependencyscope- the scope- Returns:
- this builder
- See Also:
-
factory
Convenience method. Equivalent tofactory(type, name, type, scope).- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyscope- the scope- Returns:
- this builder
- See Also:
-
alias
Convenience method. Equivalent toalias(type, Container.DEFAULT_NAME, type).- Type Parameters:
T- type- Parameters:
type- of dependencyalias- of dependency- Returns:
- this builder
- See Also:
-
alias
Maps an existing factory to a new name.- Type Parameters:
T- type- Parameters:
type- of dependencyname- of dependencyalias- of to the dependency- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- constant value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a constant value to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps a class to the given name.- Parameters:
name- namevalue- value- Returns:
- this builder
-
constant
Maps an enum to the given name.- Type Parameters:
E- value type- Parameters:
name- namevalue- value- Returns:
- this builder
-
injectStatics
Upon creation, theContainerwill inject static fields and methods into the given classes.- Parameters:
types- for which static members will be injected- Returns:
- this builder
-
contains
- Parameters:
type- type of classname- name of class- Returns:
- true if this builder contains a mapping for the given type and name.
-
contains
Convenience method. Equivalent tocontains(type, Container.DEFAULT_NAME).- Parameters:
type- type of class- Returns:
- true if this builder contains a mapping for the given type.
-
create
Creates aContainerinstance. Injects static members for classes which were registered usinginjectStatics(Class...).- Parameters:
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.- Returns:
- this builder
- Throws:
IllegalStateException- if called more than once
-
setAllowDuplicates
public void setAllowDuplicates(boolean val)
-