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.
Difference between revisions of "Eclipse4/RCP/EAS/OSGi Services"
(New page: The Eclipse 4 dependency injection framework exposes '''OSGi services''' for consumption to clients by default. This removes a lot of the boilerplate <tt>ServiceTracker</tt> code and allow...) |
|||
Line 1: | Line 1: | ||
The Eclipse 4 dependency injection framework exposes '''OSGi services''' for consumption to clients by default. This removes a lot of the boilerplate <tt>ServiceTracker</tt> code and allows clients to simply annotate a field to have an OSGi service injected. | The Eclipse 4 dependency injection framework exposes '''OSGi services''' for consumption to clients by default. This removes a lot of the boilerplate <tt>ServiceTracker</tt> code and allows clients to simply annotate a field to have an OSGi service injected. | ||
− | ==OSGi | + | ===API Comparison=== |
+ | <table border=0> | ||
+ | |||
+ | <!-- ===================================================================== --> | ||
+ | <tr> | ||
+ | <td colspan=2> | ||
+ | <h3>Service retrieval</h3> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style="background:#ebd3d2;">OSGi APIS</td> | ||
+ | <td style="background:#dbf1d2;">Eclipse 4 Dependency Injection</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style="background:#ebd3d2;"> | ||
<source lang="java"> | <source lang="java"> | ||
public class Model { | public class Model { | ||
Line 8: | Line 22: | ||
public Model(BundleContext ctxt) { | public Model(BundleContext ctxt) { | ||
− | ServiceTracker tracker = new ServiceTracker<EventAdmin, EventAdmin>(ctxt, EventAdmin.class, null); | + | ServiceTracker tracker = new ServiceTracker<EventAdmin, EventAdmin>( |
+ | ctxt, EventAdmin.class, null); | ||
tracker.open(); | tracker.open(); | ||
eventAdmin = tracker.getService(); | eventAdmin = tracker.getService(); | ||
Line 14: | Line 29: | ||
} | } | ||
</source> | </source> | ||
− | + | </td> | |
− | = | + | <td style="background:#dbf1d2;"> |
<source lang="java"> | <source lang="java"> | ||
public class Model { | public class Model { | ||
Line 22: | Line 37: | ||
} | } | ||
</source> | </source> | ||
+ | </td> | ||
+ | </tr> | ||
+ | |||
+ | </table> |
Latest revision as of 14:09, 14 April 2011
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; } |