Skip to content

Injection default implementation

Daan van Yperen edited this page Sep 29, 2015 · 1 revision

Default implementation

CachedInjector

Starting from version 0.11, CachedInjector is the default implementation of Injector. It is used when no other instance is provided via WorldConfiguration.setInjector(). The CachedInjector uses InjectionCache to cache all relevant class and field-information, to improve injection-performance for repeated access.

To resolve the values used for field-injection, the CachedInjector delegates to FieldHandler. If FieldHandler provides a non-null value for a field in a class eligible for injection (typically a class annotated with @Wire, then the value will be set for that field.

InjectionCache

The InjectionCache statically caches all relevant reflection-data needed to perform world-construction and object-injection, improving the performance of repeated calls to new World() and World.inject(). This provides significant reflection performance, especially on Android, where annotation-access is especially slow.

Note: Although the InjectionCache is instantiable, it is backed up by static field caches. Two instances of InjectionCache will use the same underlying data, so constructing new caches does not clear the cache. InjectionCache is not thread-safe.

Clone this wiki locally