E4 DI: problem with reinjecting values from different contexts [message #1712441] |
Sat, 24 October 2015 21:47 |
Frank Benoit Messages: 179 Registered: July 2009 |
Senior Member |
|
|
Hi
I use this class to test:
public class TestPojo {
@Inject
public void getText(@Optional @Named("LoggingMessage") String text ){
System.out.println("PojoMessage: "+text);
}
}
Now i create the E4 sample application with the Lifecycle class.
In the sample view, i have injected the IEclipseContext as "context" and I add a double click listener to the table:
tableViewer.addDoubleClickListener( e -> {
IStructuredSelection sel = (IStructuredSelection) e.getSelection();
String firstElement = (String) sel.getFirstElement();
IEclipseContext c = context;
for( int i = 0; c != null; c = c.getParent(), i++ ){
System.out.printf("set ctx: %d %s\n", i, c);
context.set("LoggingMessage", firstElement);
}
});
Now if i create a TestPojo with from within the sample view with its context:
pojo = ContextInjectionFactory.make( TestPojo.class, context );
I get the output each time I double click onto table items.
Now the problem, if i create the TestPojo in the E4LifeCycle#postContextCreate(IEclipseContext workbenchContext) with that workbenchContext, it only get injected once with null, not later with the text.
I see this output:
set ctx: 0 PartImplContext
PartMessage: Sample item 2
set ctx: 1 PerspectiveImplContext
set ctx: 2 TrimmedWindowImplContext
set ctx: 3 WorkbenchContext
set ctx: 4 OSGi context for bundle: org.eclipse.e4.ui.workbench
After set ctx: 3 ... I would expect the output of PojoMessage...
Is my understanding wrong?
Frank
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03811 seconds