Injection of own objects in handler [message #1100066] |
Mon, 02 September 2013 16:09 |
Marina Knieling Messages: 83 Registered: February 2013 |
Member |
|
|
Hi there,
I recently ran into a problem with DI. I have a handler (in a fragment) that dynamically generates a new window including a few parts. The fragment includes some commands and their handlers that are used in the generated window.
In the mentioned handler I have the following code:
// Convert String to Path
Path path = FileSystems.getDefault().getPath(s_path, new String[]{});
//Create child context for all import file stuff
IEclipseContext importFileContext = ctx.createChild("importFileContext");
// add a named value so that the sequencer file processor finds the path
importFileContext.set("importPath", path);
SequencerFileProcessor fileProcessor = ContextInjectionFactory.make(SequencerFileProcessor.class, importFileContext);
ctx.set(SequencerFileProcessor.class, fileProcessor);
I need this SequencerFileProcessor in another handler in the same package now (in the CanExecute method to be precise), so I thought I simply can inject it in that handler. But that doesn't work and as a result a NullPointerException is thrown.
I also tried injecting it again via ContextInjectionFactory, but I don't have access to the child context which includes needed values (the path).
[EDIT] It works in the parts I create dynamically afterwards in the handler, so the object must be available in general. Why not in the handler?
Is there anything I get wrong about Dependency Injection or why isn't this working?
Thanks in advance.
Marina
[Updated on: Mon, 02 September 2013 16:35] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02750 seconds