Dependency Injection#

Terra uses a simple annotation-based dependency injection framework to provide instances of important API objects to addons. The dependency injection framework reduces boilerplate by allowing addons to choose which objects they need to have access to.

Injecting to a Field#

To inject to a field, simply make the field non-final and non-static, and annotate it Inject.

Example#

@Inject
private Platform platform;

@Inject
private BaseAddon addon;

This example demonstrates injecting the Platform and BaseAddon instances. This is a very common scenario, as both of these objects are required for handling events

Injected Types#

The Platform instance is injected into all addons. Bootstrap addons may inject additional types into addons they load. See the Dependency Injection in Entry Points section for information about injected types in Manifest Addons.