Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Dependency injection of fields
Dependency injection of fields [message #897075] Sat, 21 July 2012 09:18 Go to next message
Markus Oley is currently offline Markus Oley
Messages: 253
Registered: July 2009
Location: Germany
Senior Member
Hi to anyone,

I have a Part and want to use dependency injection for inject some fields:

public class PreviewEditorPart {
  @Inject
  private PreviewEditorContent previewEditorContent

}


But somehow this is null if I want to do something in constructor.
If I add this to constructor and do a this.previewEditorContent = ...
it works, but I don't want to change signature.

Do I have another possibility to inject this?
Why isn't my field injected although I have a @Inject?

The constructor contains a reference to the mother - composite. Do I get this somehow by injection to avoid the necessary of having a constructor other than the default-constructor

Thank you for your help

Best regards
Markus

[Updated on: Sat, 21 July 2012 09:20]

Report message to a moderator

Re: Dependency injection of fields [message #897085 is a reply to message #897075] Sat, 21 July 2012 10:39 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 596
Registered: December 2010
Senior Member

Field injections are performed only after the object is fully created, which is after the constructor returns.

You can either do the injection as a parameter of the constructor or create another method and annotate it with @PostConstruct. This annotated method will be called by the framework right after the constructor returns AND the injector has performed all field injections. Also this method is called only once in the object lifecycle.
Re: Dependency injection of fields [message #897105 is a reply to message #897085] Sat, 21 July 2012 16:30 Go to previous message
Markus Oley is currently offline Markus Oley
Messages: 253
Registered: July 2009
Location: Germany
Senior Member
Hi Sopot,

thank you for your solutions,

Best regards
Markus
Previous Topic:What UI-classes to use, if I want to use a JavaFX-Renderer
Next Topic:E4 Problems with injecting a field that is a subclass of composite
Goto Forum:
  


Current Time: Mon Jul 28 10:24:27 EDT 2014

Powered by FUDForum. Page generated in 0.05165 seconds