Package org.apache.struts2.inject
Interface Container
- All Superinterfaces:
- Serializable
- All Known Implementing Classes:
- MockContainer
 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:
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescription<T> TgetInstance(Class<T> type) Convenience method. Equivalent togetInstance(type, DEFAULT_NAME).<T> TgetInstance(Class<T> type, String name) Gets an instance of the given dependency which was declared inContainerBuilder.getInstanceNames(Class<?> type) Gets a set of all registered names for the given type<T> TCreates and injects a new instance of typeimplementation.voidInjects dependencies into the fields and methods of an existing object.voidRemoves the scope strategy for the current thread.voidsetScopeStrategy(Scope.Strategy scopeStrategy) Sets the scope strategy for the current thread.
- 
Field Details- 
DEFAULT_NAMEDefault dependency name.- See Also:
 
 
- 
- 
Method Details- 
injectInjects dependencies into the fields and methods of an existing object.- Parameters:
- o- object to inject
 
- 
injectCreates and injects a new instance of typeimplementation.- Type Parameters:
- T- type
- Parameters:
- implementation- of dependency
- Returns:
- instance
 
- 
getInstanceGets an instance of the given dependency which was declared inContainerBuilder.- Type Parameters:
- T- type
- Parameters:
- type- of dependency
- name- of dependency
- Returns:
- instance
 
- 
getInstanceConvenience method. Equivalent togetInstance(type, DEFAULT_NAME).- Type Parameters:
- T- type
- Parameters:
- type- of dependency
- Returns:
- instance
 
- 
getInstanceNamesGets 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
 
- 
setScopeStrategySets the scope strategy for the current thread.- Parameters:
- scopeStrategy- scope strategy
 
- 
removeScopeStrategyvoid removeScopeStrategy()Removes the scope strategy for the current thread.
 
-