Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.inject
Interface Container

All Superinterfaces:
  Serializable

All Known Implementing Classes:
  MockContainer

    public interface Container

extends Serializable

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 `Foo`:

      Container c = ...;
      Foo foo = c.inject(Foo.class);

Author:
  crazybob@google.com (Bob Lee)
See Also:
  `ContainerBuilder`

Field Summary
`static String` | `DEFAULT_NAME` Default dependency name.

Method Summary
`
`<T> T`
` | `getInstance(Class<T> type)` Convenience method. Equivalent to `getInstance(type, DEFAULT_NAME)`.
`
`<T> T`
` | `getInstance(Class<T> type, String name)` Gets an instance of the given dependency which was declared in `ContainerBuilder`.
`Set<String>` | `getInstanceNames(Class<?> type)` Gets a set of all registered names for the given type
`
`<T> T`
` | `inject(Class<T> implementation)` Creates and injects a new instance of type `implementation`.
`void` | `inject(Object o)` Injects dependencies into the fields and methods of an existing object.
`void` | `removeScopeStrategy()` Removes the scope strategy for the current thread.
`void` | `setScopeStrategy(Scope.Strategy scopeStrategy)` Sets the scope strategy for the current thread.

Field Detail

### DEFAULT_NAME

    static final String DEFAULT_NAME

  Default dependency name.

  See Also:
    Constant Field Values

Method Detail

### inject

    void inject(Object o)

  Injects dependencies into the fields and methods of an existing object.

### inject

    <T> T inject(Class<T> implementation)

  Creates and injects a new instance of type `implementation`.

### getInstance

    <T> T getInstance(Class<T> type,
                      String name)

  Gets an instance of the given dependency which was declared in `ContainerBuilder`.

### getInstance

    <T> T getInstance(Class<T> type)

  Convenience method. Equivalent to `getInstance(type, DEFAULT_NAME)`.

### getInstanceNames

    Set<String> getInstanceNames(Class<?> type)

  Gets a set of all registered names for the given type

  Parameters:
    `type` - The instance type
  Returns:
    A set of registered names or empty set if no instances are registered for that type

### setScopeStrategy

    void setScopeStrategy(Scope.Strategy scopeStrategy)

  Sets the scope strategy for the current thread.

### removeScopeStrategy

    void removeScopeStrategy()

  Removes the scope strategy for the current thread.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000–2018 Apache Software Foundation. All rights reserved.