Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.inject » [javadoc | source]
com.opensymphony.xwork2.inject
public interface: Container [javadoc | source]

All Implemented Interfaces:
    Serializable

All Known Implementing Classes:
    ContainerImpl

Injects dependencies into constructors, methods and fields annotated with Inject . Immutable.

When injecting a method or constructor, you can additionally annotate its parameters with Inject and specify a dependency name. When a parameter has no annotation, the container uses the name from the method or constructor's Inject annotation respectively.

For example:

class Foo {

// Inject the int constant named "i".
@Inject("i") int i;

// Inject the default implementation of Bar and the String constant
// named "s".
@Inject Foo(Bar bar, @Inject("s") String s) {
...
}

// Inject the default implementation of Baz and the Bob implementation
// named "foo".
@Inject void initialize(Baz baz, @Inject("foo") Bob bob) {
...
}

// Inject the default implementation of Tee.
@Inject void setTee(Tee tee) {
...
}
}

To create and inject an instance of {@code Foo}:

Container c = ...;
Foo foo = c.inject(Foo.class);
Field Summary
 String DEFAULT_NAME    Default dependency name. 
Method from com.opensymphony.xwork2.inject.Container Summary:
getInstance,   getInstance,   getInstanceNames,   inject,   inject,   removeScopeStrategy,   setScopeStrategy
Method from com.opensymphony.xwork2.inject.Container Detail:
 public T getInstance(Class type)
    Convenience method. Equivalent to {@code getInstance(type, DEFAULT_NAME)}.
 public T getInstance(Class type,
    String name)
 public Set getInstanceNames(Class type)
    Gets a set of all registered names for the given type
 public  void inject(Object o)
    Injects dependencies into the fields and methods of an existing object.
 public T inject(Class implementation)
    Creates and injects a new instance of type {@code implementation}.
 public  void removeScopeStrategy()
    Removes the scope strategy for the current thread.
 public  void setScopeStrategy(Scope.Strategy scopeStrategy)
    Sets the scope strategy for the current thread.