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

Difference between revisions of "Eclipse4/RCP/Dependency Injection"

< Eclipse4‎ | RCP
m (New page: = Dependency Injection = The Eclipse 4 Application Platform provides a dependency injection framework, similar to http://springframework.org/ Spring or [[http://code.google.com/p/goog...)
 
Line 1: Line 1:
= Dependency Injection =
+
The Eclipse 4 Application Platform provides a [[http://jcp.org/en/jsr/detail?id=330 | JSR 330]]-compatible dependency injection (DI) framework, similar to [[http://springframework.org/ Spring]] or [[http://code.google.com/p/google-guice Guice]]. 
  
The Eclipse 4 Application Platform provides a dependency injection framework, similar to [[http://springframework.org/ Spring]] or [[http://code.google.com/p/google-guice Guice]].
+
Instead of PlatformUI.getWorkbench.getHelpSystem(), have the HelpSystem constructor injected.
 +
 
 +
 
 +
DI provides a number of advantages:
 +
 
 +
* Clients are able to write POJOs and list the services they need.  The DI framework provides
 +
* Useful for testing: the assumptions are placed in the DI container rather than in the client code
 +
 
 +
DI has some disadvantages too:
 +
 
 +
* Concerns about discoverability of services - cannot use code completion to find out what is available.
 +
 
 +
== DI Overview ==
 +
 
 +
*
 +
 
 +
== Using the E4AP DI Framework ==
 +
 
 +
* plugins: org.eclipse.e4.core.di, org.eclipse.e4.core.di.extensions, and org.eclipse.e4.ui.di
 +
* JSR 330 annotations: @Inject, @PostConstruct, @PreDestroy, @Named
 +
* E4AP-specific annotations: @Preference, @Event, @UIEvent
 +
* The IEclipseContext

Revision as of 14:18, 7 April 2011

The Eclipse 4 Application Platform provides a [| JSR 330]-compatible dependency injection (DI) framework, similar to [Spring] or [Guice].

Instead of PlatformUI.getWorkbench.getHelpSystem(), have the HelpSystem constructor injected.


DI provides a number of advantages:

  • Clients are able to write POJOs and list the services they need. The DI framework provides
  • Useful for testing: the assumptions are placed in the DI container rather than in the client code

DI has some disadvantages too:

  • Concerns about discoverability of services - cannot use code completion to find out what is available.

DI Overview

Using the E4AP DI Framework

  • plugins: org.eclipse.e4.core.di, org.eclipse.e4.core.di.extensions, and org.eclipse.e4.ui.di
  • JSR 330 annotations: @Inject, @PostConstruct, @PreDestroy, @Named
  • E4AP-specific annotations: @Preference, @Event, @UIEvent
  • The IEclipseContext

Back to the top