Injection of own objects in handler [message #1100066] |
Mon, 02 September 2013 12:09  |
Eclipse User |
|
|
|
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 12:35] by Moderator
|
|
|
|
|
|
Re: Injection of own objects in handler [message #1100670 is a reply to message #1100667] |
Tue, 03 September 2013 08:29  |
Eclipse User |
|
|
|
All declarative method calls (@Execute, @CanExecute, @PersistState,
@Presist, ...) in the end anything invoked through CIF#invoke() can have
any number of arguments.
Tom
On 03.09.13 14:24, Marina Knieling wrote:
> That worked. Thanks a lot. That was easy ;)
> Is there any information on that topic in a more "prominent" place like
> tutorials or wiki? As I said I've read in some tutorial that @Execute
> includes @Inject, but not for @CanExecute. I think there wouldn't be
> such questions if this was written anywhere. Maybe I didn't see that
> information.
|
|
|
Powered by
FUDForum. Page generated in 0.35502 seconds