Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Re: [e4] How to get ready ?
Re: [e4] How to get ready ? [message #576503] Fri, 21 May 2010 13:55
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Declare them as Declarative Services and consume them through:
* OSGi-Service-API
* Set up your own Eclipse 4 DI-Container which injects them.

Setting up an Eclipse DI-Container and context is really very easy.

Take a look here how to bootstrap such a container from scratch:

0. Assuming your class looks like this:
--------8<--------
package com.project.my

import javax.inject.Inject;

public class Bla {
@Inject
public void setService(IMyOSGiService service) {
// ...
}
}

--------8<--------


1. Setup DI-Container
--------8<--------
> Bundle bundle = FrameworkUtil.getBundle(IEclipseContextServiceFactory.class) ;
> BundleContext bundleContext = bundle.getBundleContext();
> IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
>
> final IEclipseContext appContext = serviceContext.createChild("WorkbenchContext"); //$NON-NLS-1$
> IExtensionRegistry registry = RegistryFactory.getRegistry();
> ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(registry);
> appContext.set(IContributionFactory.class.getName(),contribu tionFactory);
>
--------8<--------

2. Create an instance
--------8<--------
> IContributionFactory factory = (IContributionFactory) appContext.get(IContributionFactory.class);
> instance = factory.create("platform:/plugin/com.project.my/com.project.my.Bla ", appContext);
--------8<--------

You get an service which is in the OSGi-Service registry injected
automagically.

Tom

You can see this is a more generic action here:
http://dev.eclipse.org/viewcvs/index.cgi/e4/org.eclipse.e4.t ools/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclip se/e4/tools/emf/editor3x/compat/



Am 21.05.10 15:35, schrieb Christophe Fondacci:
> I think so... but since OSGi services seems to be wrapped by "eclipse
> services" in the UI layer (the org.eclipse.ui.services extension point
> and service factories which Paul mentioned), I wanted to know what was
> the best way to declare my services...
>
> ..for now (3.x) and for e4 "portability".
>
> Thanks,
> Christophe
> http://www.nextep-softwares.com
Previous Topic:Re: [e4] How to get ready ?
Next Topic:Customizing the workbench window
Goto Forum:
  


Current Time: Thu Mar 28 12:05:57 GMT 2024

Powered by FUDForum. Page generated in 0.24998 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top