-
Notifications
You must be signed in to change notification settings - Fork 115
Customized injection
By default, the World injects dependencies as described for @Wire during construction. This is done by an Injector registered with the WorldConfiguration. If greater control is needed, you can provide your own Injector
with a customized FieldHandler
.
The below code creates a FieldHandler which will contain two field FieldResolvers: ArtemisFieldResolver and CustomFieldsResolver. In this case, the WiredFieldResolver is not part of the world configuration, so unless the CustomFieldsResolver handles fields annotated with @Wire
, these fields will not be injected. Systems, Managers, ComponentMappers & EntityFactories will still be injected.
FieldHandler fieldHandler = new FieldHandler(new InjectionCache());
fieldHandler.addFieldResolver(new CustomFieldsResolver());
Injector injector = new CachedInjector().setFieldHandler(fieldHandler);
World world = new World(new WorldConfiguration().setInjector(injector));
The injector can be customized using WorldConfiguration.setInjector
prior to calling new World()
.
The injector determines which classes are eligible for dependency injection, and delegates to a FieldHandler
to resolve the actual value for each field in a class.
Artemis provides the CachedInjector
which should be useful in most cases. By configuring aIn the below example, a new world is created
- FieldHandler providing value for fields eligible for dependency injection. Multiplexes multiple FieldResolvers.
- FieldResolver provides values for injection.
- Injection default implementation
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference