Annotation Type Inject


@Retention(CLASS) @Target(FIELD) public @interface Inject
Inject classes in a component instance field. The following injections are currently performed, depending on the type of the field this annotation is applied on:
  • BundleContext: the bundle context of the bundle
  • DependencyManager: the dependency manager instance
  • Component: the component instance of the dependency manager

Usage Examples

 @Component
 class X implements Z {
     @Inject
     BundleContext bundleContext;
   
     @Inject
     Component component;
     
     @Inject
     DependencyManager manager;
   
     OtherService otherService;
   
     @Init
     void init() {
         System.out.println("Bundle Context: " + bundleContext);
         System.out.println("Manager: " + manager);
         
         // Use DM API for defining an extra service dependency
         componnent.add(manager.createServiceDependency()
                               .setService(OtherService.class)
                               .setRequired(true)
                               .setInstanceBound(true));
     }
     
     @Start
     void start() {
         System.out.println("OtherService: " + otherService);
     }
 }
 
Author:
Felix Project Team