|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IInjector
The injector
is used to build objects for your application.
It does so by maintaining a map of keys
and associated
bindings
. The map is created by modules
.
Some bindings are present automatically:
- The Injector
itself.
- For any IBinding
(binding of type T), there is also
a provider
of type T.
To create an injector
, use the class CommonsInject
.
Method Summary | ||
---|---|---|
|
getInstance(Class<T> pType)
Returns an instance of pType , if a matching binding is present. |
|
|
getInstance(Class<T> pType,
String pName)
Returns an instance of the given type, with the given name, if a matching binding is present. |
|
|
getInstance(IKey<T> pKey)
Returns an instance of the binding that has been registered for the given key. |
|
void |
injectMembers(Object pInstance)
Injects members into the given instance, as if it where created by the injector itself. |
|
|
requireInstance(Class<T> pType)
Returns an instance of pType , if a matching binding is present. |
|
|
requireInstance(Class<T> pType,
String pName)
Returns an instance of the given type, with the given name, if a matching binding is present. |
|
|
requireInstance(IKey<T> pKey)
Returns an instance of the binding that has been registered for the given key. |
Method Detail |
---|
<T> T getInstance(Class<T> pType)
pType
, if a matching binding is present.
This is a shortcut for
getInstance(pType, "")or
getInstance(pType, Key.NO_NAME)
pType
- The requested type.
getInstance(Class, String)
,
getInstance(IKey)
,
requireInstance(Class)
<T> T getInstance(Class<T> pType, String pName)
Key key = new Key(pType, pName); getInstance(key)or
Key key = new Key(pType, pName, Key.NO_ANNOTATIONS); getInstance(key)
pType
- The requested type.pName
- The requested objects name.
getInstance(IKey)
,
requireInstance(Class, String)
<T> T getInstance(IKey<T> pKey)
pKey
- A binding key, for which a binding has been registered.
getInstance(Class)
,
getInstance(Class, String)
,
requireInstance(IKey)
<T> T requireInstance(Class<T> pType) throws NoSuchBindingException
pType
, if a matching binding is present.
This is a shortcut for
requireInstance(pType, "")or
requireInstance(pType, Key.NO_NAME)
pType
- The requested type.
NoSuchBindingException
- No matching binding has been registered with
the injector.getInstance(Class, String)
,
getInstance(IKey)
,
requireInstance(Class)
<T> T requireInstance(Class<T> pType, String pName) throws NoSuchBindingException
Key key = new Key(pType, pName); requireInstance(key)or
Key key = new Key(pType, pName, Key.NO_ANNOTATIONS); requireInstance(key)
pType
- The requested type.pName
- The requested objects name.
NoSuchBindingException
- No matching binding has been registered with
the injector.getInstance(Class, String)
,
requireInstance(Class)
,
requireInstance(IKey)
<T> T requireInstance(IKey<T> pKey) throws NoSuchBindingException
pKey
- A binding key, for which a binding has been registered.
NoSuchBindingException
- No matching binding has been registered with
the injector.getInstance(IKey)
,
requireInstance(Class)
,
requireInstance(Class, String)
void injectMembers(Object pInstance)
injector
itself. In other words, fills fields
and invokes methods annotated with @Inject, assuming that a binding
is present for those fields, and method parameters.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |