Time for action – creating a simple service
POJOs can be instantiated and made available in the E4 context, such that they can be injected into other classes or created on demand. This allows an application to be built in a flexible manner without tight coupling between services.
- Create a class
StringService
in thecom.packtpub.e4.application
package with a@Creatable
annotation, and aprocess
method that takes a string and returns an uppercase version:import org.eclipse.e4.core.di.annotations.Creatable; @Creatable public class StringService { public String process(String string) { return string.toUpperCase(); } }
- Add an injectable instance of
StringService
to theRainbow
class:@Inject private StringService stringService;
- Use the injected
stringService ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.