Order of injection when mixing constructor/setter injection (and even subclassing)

2,132 views
Skip to first unread message

David Nouls

unread,
Mar 7, 2012, 4:41:35 AM3/7/12
to google...@googlegroups.com
Hi,
 
I ran into a wall with GIN/Guice when it comes to mixing setter and constructor injection. I could not find any wiki page on the official guice page so I though I should ask the question here (before potentially creating an issue on gin or guice).
 
I have an object hierarchy that combines constructor injection and setter injection.
 
public class Base {
   @Inject Base( Something pDependency )
 
  @Inject setValidator( Validator validator ) {
 
  }
}

Sam Berlin

unread,
Mar 7, 2012, 9:00:58 AM3/7/12
to google...@googlegroups.com

What is the question?

sam

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/AGcouYd9Cy8J.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

Thomas Broyer

unread,
Mar 7, 2012, 10:02:50 AM3/7/12
to google...@googlegroups.com
Is this what you're looking for: http://code.google.com/p/google-guice/wiki/InjectionPoints

Injections are performed in a specific order. All fields are injected and then all methods. Within the fields, supertype fields are injected before subtype fields. Similarly, supertype methods are injected before subtype methods.

Of course, constructors are injected before methods and fields, as you have to construct an instance before injecting its members.

Reply all
Reply to author
Forward
0 new messages