Eclipse contexts & Gemini blueprint [message #989974] |
Mon, 10 December 2012 05:28  |
Eclipse User |
|
|
|
I'm developing a rcp application with gemini blueprint, and I am getting confused with eclipse contexts :
1. The eclipse context I get with DI in my UI code is a WorkbenchContext (or a child of it), which parent is an EclipseOsgiContext for bundle org.eclipse.e4.ui.workbench.
2.The eclipse context that I get with this snippet
EclipseContextFactory.getServiceContext(BundleContext)
invoked from a spring bean using the injected BundleContext is an EclipseOsgiContext for my own bundle, which is different from the context I get in point 1 above.
OSGi services are declared in the blueprint xml configuration (with <reference> tag), and are available for DI in my UI code, while other spring beans (declared with standard <bean>) are not.
I would like to be able to inject standard spring beans into my UI code. Is there a way to either get the UI eclipse context from a spring bean (so that I can register the bean in the UI context), or is there another way to achieve it ?
Thanks in advance for any solution.
--
Gaëtan
|
|
|
|
|
|
Re: Eclipse contexts & Gemini blueprint [message #992394 is a reply to message #992271] |
Fri, 21 December 2012 09:36  |
Eclipse User |
|
|
|
I would prefer to not register Foo as an OSGi service. The idea is to register most of "local" spring beans (like Foo) in the Eclipse context of my plugin.
I tried a few things and came to this solution :
1. In OSGiApplicationContext for my plugin:
1.1. Define a bean of type IEclipseContext with EclipseContextFactory.create() named 'eclipseContext'
1.2. Define a bean post-processor that register beans in the eclipseContext
2. Register a lifeCycleURI class with @PostContextCreate in my plugin:
@PostContextCreate
public void exposeSpringBeans(IEcliseContext context) {
// 2.1. Get (and maybe wait until loaded) ApplicationContext from my BundleContext
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
ApplicationContext ac = getApplicationContext(bundleContext);
// 2.2. Get the eclipseContext that was created and populated during AC creation
IEclipseContext eclipseSpringContext = ac.getBean("eclipseContext", IEclipseContext.class);
// context.getParent() is the context for 'org.eclipse.e4.ui.workbench' bundle
// this context has no parent
// 2.3. Set the spring eclipse context as the parent of this one
IEclipseContext eclipseUiPluginContext = context.getParent();
eclipseUiPluginContext.setParent(eclipseSpringContext);
}
It finally works: I can inject a Spring bean in a UI component using @Inject.
But is it legal ? I mean, can I set a parent to the EclipseContextOSGi ? API won't prevent it, but I'm afraid to tweak something linked with OSGi.
|
|
|
Powered by
FUDForum. Page generated in 0.24663 seconds