Constructor Injection along with parameters from super-class

68 views
Skip to first unread message

Petar Aleksic

unread,
Oct 31, 2015, 7:21:04 PM10/31/15
to google-guice
I am extending a class from a library. This class from a library has a constructor and some parameters that are not injected:

//Constructor
public externalClass(SomeParam A, SomeOtherParam B) {
   
...
}

The subclass's constructor looks something like this:

//Constructor of class that exteds externalClass
public subClass(SomeParam A, SomeOtherParam B, ParamToBeInjected C) {
   
super(SomeParam A, SomeOtherParam B);
    this.paramToBeInjected = C;
    ...
}

Now, the problem is that only dependency I want to inject in subClass is the third parameter, ParamToBeInjected C . The first two are handled by the externalClass i.e. the parent class of  subClass.
If I annote the constructor with @Inject, it  wont't work since an attempt to inject all the constructor arguments will be made. If, on the other hand, the constructor is not annoted, the error "Could not find a suitable constructor..." occurs. Any ideas, suggestions?

Thanks.
Regards



Alexander Openkowski

unread,
Oct 31, 2015, 7:45:44 PM10/31/15
to google...@googlegroups.com
--
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 http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/d6e0d047-a605-4a46-9fca-2243cd16b725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages