Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Eclipse4/RCP/EAS/Obtaining Services

< Eclipse4‎ | RCP‎ | EAS
Revision as of 21:57, 11 April 2011 by Unnamed Poltroon (Talk)

The services are set by the dependency injection framework when your objects gets instantiated (or explicitly injected).

Injection of objects

The services that should be injected can be marked by the @Inject annotation.

Fields

public class AccountsPart {
  @Inject
  private Logger logger;
}

Methods

public class AccountsPart {
  private Logger logger;
 
  @Inject
  void setLogger(Logger logger) {
    this.logger = logger;
  }
}

Injection for method invocation

Here is an example of a handler's method being invoked by the framework with its parameters being provided through dependency injection.

public class ShowPartHandler {
  @Execute
  void execute(EPartService partService) {
    String partId = /* retrieve the desired id */;
    partService.showPart(partId, EPartService.PartState.ACTIVATE);
  }
}

Back to the top