public class Injector extends Object
Contains the micro kernel which keeps track of all parts and injects them where required. We consider this a micro kernel, as it doesn't directly know any annotations. It rather delegates the work to classes which implement defined interfaces. Therefore the implementation is rather short but easily extensible.
Parts are commonly added via subclasses of
ClassLoadAction. These scan each class in the classpath
and instantiate and insert them into the
MutableGlobalContext if required. Most of these
ClassLoadAction implementations trigger on annotations. A prominent example is the
AutoRegisterAction which loads all classes wearing the
annotation. Subclasses of ClassLoadAction are discovered automatically.
Accessing parts can be done in two ways. First, one can access the current
context(). This can be used to retrieve parts by class or by class and name. The second way
to access parts is to use marker annotations like
Parts. Again, these annotations are not processed by the micro kernel itself, but by
To process all annotations of a given Java object,
GlobalContext.wire(Object) can be used. This will
be automatically called for each part which is auto-instantiated by a ClassLoadAction.
Also all annotations on static fields are processed on system startup. This is a simple trick to pass a part to objects which are frequently created and destroyed.
|Modifier and Type||Field and Description|
Logger used by the injection framework.
|Modifier and Type||Method and Description|
Provides access to the global context, containing all parts This can also be loaded into a class field using the
Returns a list of all loaded classes.
Initializes the framework.
public static final Log LOG
This is automatically invoked by
classpath- the classpath used to enumerate all classes to be scanned
public static GlobalContext context()
This can also be loaded into a class field using the
Part annotation and
GlobalContext as field type.
Copyright © 2018. All rights reserved.