Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: for the plan.

Jump to: navigation, search

Eclipse4/RCP/EAS/Obtaining Services

< Eclipse4‎ | RCP‎ | EAS
Revision as of 13:08, 14 April 2011 by (Talk | contribs) (Service retrieval through the context)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.


public class AccountsPart {
  private Logger logger;


public class AccountsPart {
  private Logger logger;
  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 {
  void execute(EPartService partService) {
    String partId = /* retrieve the desired id */;
    partService.showPart(partId, EPartService.PartState.ACTIVATE);

Service retrieval through the context

Services can also be retrieved from the IEclipseContext using its get(Class<T>) and get(String) methods.


EPartService partService = context.get(EPartService.class);


MPart part = (MPart) context.get(IServiceConstants.ACTIVE_PART);

Back to the top