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 #535192] Fri, 21 May 2010 09:55
Thomas Schindl is currently offline Thomas Schindl
Messages: 5252
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:Re: [e4] How to get ready ?
Goto Forum:
  


Current Time: Mon Jul 28 22:54:18 EDT 2014

Powered by FUDForum. Page generated in 0.02474 seconds