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);
   }
}
Advertisements
Categories: e4
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: