|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Container
Injects dependencies into constructors, methods and fields annotated with
@Inject
.
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 get an instance of Foo
:
Container c = ...; Key<Foo> fooKey = Key.get(Foo.class); Factory<Foo> fooFactory = c.getFactory(fooKey); Foo foo = fooFactory.get();
ContainerBuilder
Method Summary | ||
---|---|---|
|
findBindingsByType(TypeLiteral<T> type)
Finds all bindings to the given type. |
|
|
getBinding(Key<T> key)
Gets a binding for the given key. |
|
java.util.Map<Key<?>,Binding<?>> |
getBindings()
Gets all bindings. |
|
|
getCreator(java.lang.Class<T> implementation)
Gets a factory which injects the given class's constructor and creates new instances of T . |
|
|
getFactory(Key<T> key)
Gets the factory bound to the given key. |
|
void |
injectMembers(java.lang.Object o)
Injects dependencies into the fields and methods of an existing object. |
Method Detail |
---|
void injectMembers(java.lang.Object o)
<T> Factory<T> getCreator(java.lang.Class<T> implementation)
T
.
<T> Factory<T> getFactory(Key<T> key)
java.util.Map<Key<?>,Binding<?>> getBindings()
<T> Binding<T> getBinding(Key<T> key)
<T> java.util.List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |