Skip to main content


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 13:18 Go to next message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
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 13:20]

Report message to a moderator

Re: Dependency injection of fields [message #897085 is a reply to message #897075] Sat, 21 July 2012 14:39 Go to previous messageGo to next message
Eclipse UserFriend
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 20:30 Go to previous message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
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: Tue Apr 23 15:42:29 GMT 2024

Powered by FUDForum. Page generated in 0.02841 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top