Discussion:
Mixing Field and Constructor injection
Tavian Barnes
2017-11-13 16:24:53 UTC
Permalink
You can use a MembersInjector<PTRS> to trigger field/method injection.
Hi Guice team,
I have a usecase where I am using an external jar that is based on Spring,
while my code is on Google guice.
I am trying to inject dependencies in a class of my dependency jar, by
writing modules.
public class PTRS {
@Inject
private Event countEvent;
@Inject
private Event durationEvent;
private GeoServiceClient gClient;
private AssignmentClient aClient;
public void setGeoServiceClient(GeoServiceClient
client){this.gClient=client}
public void setAssignmentClient(AssignmentClient
client){this.aClient=client}
}
NullPointerException for countEvent and durationEvent. :(
My uses following provider class to create an object to bind with PTRS
class.
class PTRSProvider implements Provider<PTRS>
{
public PTRSProvider(){
}
@Override
public PTRSProvider get() {
PTRS ptrs = new PTRS();
ptrs.setGeoServiceClient(new client());
ptrs.setAssignmentServiceClient(new client());
return ptrs;
}
}
Can you please guide me as to how I can combine both Setter and Field
injection in this case?
Any help would be appreciated! :)
Regards.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/dedf14c2-2f45-4d23-bc50-9003c81bc5c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...