Annotation Type Composition
Annotates a method returning the list of objects which are part of a Component implementation.
When implementing complex Components, you often need to use more than one object instances.
Moreover, several of these instances might want to have dependencies injected, as well as lifecycle
callbacks invoked, like the methods annotated with
Init, Start, Stop,
Destroy annotations. In such cases you can tell the dependency manager which instances to
consider, by annotating a method in your Component, returning a list of objects which are part
of the implementation.
This annotation may be applied on a method which is part of class annotated with either a Component,
AspectService, or AdapterService.
Usage Examples
Here, the "MyComponent" component is composed of the Helper class, which is also injected with service dependencies. The lifecycle callbacks are also invoked in the Helper (if the Helper defines them):
class Helper {
volatile LogService logService; // Injected
void start() {} // lifecycle callback
void bind(OtherService otherService) {} // injected
}
@Component
class MyComponent {
// Helper which will also be injected with our service dependencies
private Helper helper = new Helper();
@Composition
Object[] getComposition() {
return new Object[] { this, helper };
}
@ServiceDependency
private LogService logService; // Helper.logService will be also be injected, if defined.
@Start
void start() {} // the Helper.start() method will also be called, if defined
@ServiceDependency
void bind(OtherService otherService) {} // the Helper.bind() method will also be called, if defined
}
- Author:
- Felix Project Team