And those are the concrete versions :
1-CustomerServiceConsumer
2-CustomerAccountsServiceConsumer
3-CustomerCreditCardsServiceConsumer
Some how I want inject CustomerAccountsServiceConsumer &
CustomerCreditCardsServiceConsumer into getDependencies() in
CustomerServiceConsumer
Can this be done ?
* I also want to note that I'm using GIN , not Guice but I think they
have the same concept .
Thanks in advance
Aladdin
I personally prefer using constructor injection, and putting @Inject
on a method like getDependencies() seems weird to me, especially since
it's part of the interface. It's not always possible to use
constructor injection if another framework is creating your objects,
but for your example I'll assume it is possible.
If you use constructor injection and inject
CustomerAccountsServiceConsumer, and CustomerAccountsServiceConsumer
into CustomerServiceConsumer then you can implement the
getDependencies() yourself:
class CustomerServiceConsumer extends ServiceConsumer {
CustomerAccountsServiceConsumer accountConsumer;
CustomerCreditCardsServiceConsumer creditCardConsumer;
@Inject
CustomerServiceConsumer(CustomerAccountsServiceConsumer
accountConsumer, CustomerCreditCardsServiceConsumer
creditCardConsumer) {
this.accountConsumer = accountConsumer;
this.creditCardConsumer = creditCardConsumer;
}
@Override
public List<ServiceConsumer> getDependencies() {
return Arrays.asList(new ServiceConsumer[] { accountConsumer,
creditCardConsumer } );
}
Using default bindings, when you ask Guice to create an instance of
CustomerServiceConsumer, it will first create a new
CustomerAccountsServiceConsumer and then a new
CustomerCreditCardsServiceConsumer and pass those instances into the
constructor of CustomerServiceConsumer.
-Scott
@Thomas I think you MultiBinder is what I need but I'm using GIN and
it's not supported :(
Any other suggestions ?
--To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/pEypSi01Q-0J.
You received this message because you are subscribed to the Google Groups "google-guice" group.
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.