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.

  1. Create a class StringService in the com.packtpub.e4.application package with a @Creatable annotation, and a process 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();
      }
    }
  2. Add an injectable instance of StringService to the Rainbow class:
    @Inject
    private StringService stringService;
  3. 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.