public interface IInjector
Matching of methods and fields to be injected is performed using the annotations defined in packages javax.inject and org.eclipse.e4.core.services.annotations.
The injection of values is generally done as a number of calls. User objects that want to
finalize the injected data (for instance, to perform calculations based on multiple injected
values) can place such calculations in a method with the PostConstruct
annotation.
When injecting values, all fields are injected prior to injection of methods. When values are removed from the context or the context is disposed, injection of null values occurs in the reverse order: methods and then fields. As a result, injection methods can safely make use of injected field values. The order in which methods are injected is undefined, so injection methods should not rely on other injection methods having been run already. Methods and field on superclasses are injected before methods in fields on the subclasses.
When supplier is disposed, the injector will attempt to notify all injected objects by
calling methods with the PreDestroy
annotation.
Modifier and Type | Field and Description |
---|---|
static Object |
NOT_A_VALUE
Methods may return this to indicate that the requested object was not found
wherever
null can be a valid return value. |
Modifier and Type | Method and Description |
---|---|
IBinding |
addBinding(Class<?> clazz)
Creates a binding for the specified class and adds it to the injector.
|
IBinding |
addBinding(IBinding binding)
Adds binding to the injector.
|
void |
inject(Object object,
PrimaryObjectSupplier objectSupplier)
Injects data from the supplier into a domain object.
|
Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
Object defaultValue,
PrimaryObjectSupplier objectSupplier)
Call the annotated method on an object, injecting the parameters from the supplier.
|
Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
Object defaultValue,
PrimaryObjectSupplier objectSupplier,
PrimaryObjectSupplier localSupplier)
Call the annotated method on an object, injecting the parameters from the suppliers.
|
Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
PrimaryObjectSupplier objectSupplier)
Call the annotated method on an object, injecting the parameters from the supplier.
|
<T> T |
make(Class<T> clazz,
PrimaryObjectSupplier objectSupplier)
Obtain an instance of the specified class and inject it with the data from the supplier.
|
<T> T |
make(Class<T> clazz,
PrimaryObjectSupplier objectSupplier,
PrimaryObjectSupplier staticSupplier)
Obtain an instance of the specified class and inject it with the data from the supplier.
|
void |
setDefaultSupplier(PrimaryObjectSupplier objectSupplier)
Specifies object supplier to inject internally created objects,
such as extended object suppliers.
|
void |
uninject(Object object,
PrimaryObjectSupplier objectSupplier)
Un-injects the supplier from the object.
|
static final Object NOT_A_VALUE
null
can be a valid return value.void inject(Object object, PrimaryObjectSupplier objectSupplier) throws InjectionException
object
- the object to perform injection onobjectSupplier
- primary object supplier for the injectionInjectionException
- if an exception occurred while performing this operationvoid uninject(Object object, PrimaryObjectSupplier objectSupplier) throws InjectionException
object
- the domain object previously injected with the supplier's dataobjectSupplier
- primary object supplier for the injectionInjectionException
- if an exception occurred while performing this operationObject invoke(Object object, Class<? extends Annotation> qualifier, PrimaryObjectSupplier objectSupplier) throws InjectionException
If no matching method is found on the class, an InjectionException will be thrown.
object
- the object on which the method should be calledqualifier
- the annotation tagging method to be calledobjectSupplier
- primary object suppliernull
InjectionException
- if an exception occurred while performing this operationObject invoke(Object object, Class<? extends Annotation> qualifier, Object defaultValue, PrimaryObjectSupplier objectSupplier) throws InjectionException
If no matching method is found on the class, the defaultValue will be returned.
object
- the object on which the method should be calledqualifier
- the annotation tagging method to be calleddefaultValue
- a value to be returned if the method cannot be called, might be null
objectSupplier
- primary object suppliernull
InjectionException
- if an exception occurred while performing this operationObject invoke(Object object, Class<? extends Annotation> qualifier, Object defaultValue, PrimaryObjectSupplier objectSupplier, PrimaryObjectSupplier localSupplier) throws InjectionException
If no matching method is found on the class, the defaultValue will be returned.
object
- the object on which the method should be calledqualifier
- the annotation tagging method to be calleddefaultValue
- a value to be returned if the method cannot be called, might be null
objectSupplier
- primary object supplierlocalSupplier
- primary object supplier, values override objectSuppliernull
InjectionException
- if an exception occurred while performing this operation<T> T make(Class<T> clazz, PrimaryObjectSupplier objectSupplier) throws InjectionException
T
- the type of the object to be createdclazz
- the class to be instantiatedobjectSupplier
- primary object supplier for the injectionInjectionException
- if an exception occurred while performing this operationScope
,
Singleton
<T> T make(Class<T> clazz, PrimaryObjectSupplier objectSupplier, PrimaryObjectSupplier staticSupplier) throws InjectionException
If values for the same key present in both the object supplier and the static supplier, the values from the static supplier are injected. Injected values from the static supplier are not tracked and no links between the static supplier and the object are established.
T
- the type of the object to be createdclazz
- the class to be instantiatedobjectSupplier
- primary object supplier for the injectionstaticSupplier
- additional object supplier for the injection, changes in injected values are not trackedInjectionException
- if an exception occurred while performing this operationScope
,
Singleton
IBinding addBinding(Class<?> clazz)
clazz
- the class that the injector should be aware ofIBinding addBinding(IBinding binding)
binding
- the binding to add to the injectorvoid setDefaultSupplier(PrimaryObjectSupplier objectSupplier)
objectSupplier
- the object supplier used to inject objects
implicitly created by this injector
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.