public interface Injector
Allows you to retrieve singletons and create new instances. By default, it supports field and constructor injection
and executes methods annotated with @PostConstruct. You can obtain an injector and customize its behavior
with the InjectorBuilder.
| Modifier and Type | Method and Description |
|---|---|
<T> T |
createIfHasDependencies(Class<T> clazz)
Creates an instance of the given class if all of its dependencies are available.
|
<T> T |
getIfAvailable(Class<T> clazz)
Returns the singleton of the given class if available.
|
<T> T |
getSingleton(Class<T> clazz)
Retrieves or instantiates an object of the given type (singleton scope).
|
<T> T |
newInstance(Class<T> clazz)
Request-scoped method to instantiate a new object of the given class.
|
void |
provide(Class<? extends Annotation> annotation,
Object object)
Processes an annotation with an associated object.
|
<T> void |
register(Class<? super T> clazz,
T object)
Registers an object as the singleton of the given class.
|
<T,P extends javax.inject.Provider<? extends T>> |
registerProvider(Class<T> clazz,
Class<P> providerClass)
Registers the provider class to instantiate a given class.
|
<T> void |
registerProvider(Class<T> clazz,
javax.inject.Provider<? extends T> provider)
Registers a provider for the given class.
|
<T> Collection<T> |
retrieveAllOfType(Class<T> clazz)
Returns all known singletons of the given type.
|
<T> void register(Class<? super T> clazz, T object)
T - the type to register the object forclazz - the class to register the object forobject - the object<T> void registerProvider(Class<T> clazz, javax.inject.Provider<? extends T> provider)
T - the class' typeclazz - the class to register the provider forprovider - the provider<T,P extends javax.inject.Provider<? extends T>> void registerProvider(Class<T> clazz, Class<P> providerClass)
clazz has to
be instantiated, the providerClass will be instantiated.T - the class' typeP - the provider's typeclazz - the class to register the provider forproviderClass - the class of the providervoid provide(Class<? extends Annotation> annotation, @Nullable Object object)
annotation - the annotationobject - the object<T> T getSingleton(Class<T> clazz)
T - the class' typeclazz - the class to retrieve the value for<T> T newInstance(Class<T> clazz)
T - the class' typeclazz - the class to instantiate@Nullable <T> T getIfAvailable(Class<T> clazz)
null. Calling this method will never create any new objects.T - the class' typeclazz - the class to retrieve the instance for@Nullable <T> T createIfHasDependencies(Class<T> clazz)
Note: Currently, all dependencies of the class need to be registered singletons for a new instance to be created. This limitation may be lifted in future versions.
T - the class' typeclazz - the class to construct if possiblenull if any dependency does not already exist<T> Collection<T> retrieveAllOfType(Class<T> clazz)
Object as clazz will return all known singletons.T - the class' typeclazz - the class to retrieve singletons ofCopyright © 2017. All rights reserved.