Home > e4 > Use E4 DI on Legacy ViewPart

Use E4 DI on Legacy ViewPart

What if you are developing Eclipse IDE plugin, You should have to use old extension points to contribute View or Editor even it’s target platform is Juno.

In this case, You may want to use DI(Dependency Injection Feature of E4) on your contribution.

You can get IEclipseContext through IServiceLocator, and you can inject dependencies with ContextInjectctionFactory:

@Override
public class AddonView extends ViewPart {
   @Inject
   private MApplication application;

   @Override
   public void init(IViewSite site) throws PartInitException {
      super.init(site);

      IEclipseContext context = (IEclipseContext) site.getService(IEclipseContext.class);
      ContextInjectionFactory.inject(this, context);
   }
}
Categories: e4
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment