Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Eclipse4/RCP/EAS/OSGi Services

< Eclipse4‎ | RCP‎ | EAS

The Eclipse 4 dependency injection framework exposes OSGi services for consumption to clients by default. This removes a lot of the boilerplate ServiceTracker code and allows clients to simply annotate a field to have an OSGi service injected.

API Comparison

Service retrieval

OSGi APIS Eclipse 4 Dependency Injection
public class Model {
 
  private EventAdmin eventAdmin;
 
  public Model(BundleContext ctxt) {
    ServiceTracker tracker = new ServiceTracker<EventAdmin, EventAdmin>(
        ctxt, EventAdmin.class, null);
    tracker.open();
    eventAdmin = tracker.getService();
  }
}
public class Model {
  @Inject
  private EventAdmin eventAdmin;
}

Back to the top