Tuesday 3 March 2015



The plugins that provide common annotations for DI (Dependency Annotations) in Eclipse E4 are

javax.inject
javax.annotation
org.eclipse.e4.core.di
org.eclipse.e4.ui.services

The common annotations are

@Inject
@PostConstruct
@PreDestroy
@Optional
@Named
@Creatable

The common Interfaces and Constants are present in interface IServiceConstants.

Usage and Explanations:

@Inject - Used for Injecting the value which the framework has. Developer needs to ensure that the injected object instance is already present with the framework

class Employee {
    String name;
    String address;
    @Inject EmployeeDB database;

    @Inject
    public void setEmployeeDetailsFromUI(MPart part) {
           //Some code here
    }
}

@PostConstruct - Method annotated with this one are called after an object instance is created. Typically useful as an entry method for a part instance where developers can start creating the controls.

@PreDestroy - Method annotated with this one are called before the object is destroyed.

@Optional - Conveys to the framework that this variable is passed with the value only if the framework has the value else framework can pass null to the variable. Can be used as parameter to a method or as a field.

@Named - Can be paired with other annotations and meaning is that, the annotation is valid for the string passed with the @Named

@Creatable - Framework creates the class (if all attributes are creatable) and is injected.

The objects are looked up in the contexts that are made available by the framework. If the objects are available in the context, they are injected.

The framework start to look for the object for injection in the following order.

Part
Perspective
Window
Workbench
OSGi

Inorder to make that a class is present with the annotation, it has be either directly injected  (in this case, the framework will look for the dependencies and does injection for the dependencies as well) or connected to the application model which the framework will parse.

Like wise when connected to the application model or manually mentioned, the methods can be annotated to listen for specific events.

Reference: http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-4-dependency-injection-basics/
Annotations: http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-6-behavior-annotations/

Gallery

Object Oritented, Git

Most Commented

OOAD

Contact Form

Name

Email *

Message *

2014 © Planer - Responsive Blogger Magazine Theme
Planer theme by Way2themes