Thank you all for the great replies,

I wanted to use IoC concept to avoid having dependencies hard-coded in
my class (at least this what I thought).

Having something like :

CustomerServiceConsumer(CustomerAccountsServiceConsumer
accountConsumer, CustomerCreditCardsServiceConsumer
creditCardConsumer) { ... }

Makes little sense to me as the class have to change every time I need
to have more dependencies .

let me try to be more clear  ,

public class CustomerServiceConsumer extends ServiceConsumer<Client>{

        @Override
        public void consume() {
                // consume code for client goes here

                // Then load dependencies
                for (ServiceConsumer<?> d:getDependencies()){
                        d.consume();
                }
        }

        @Inject
        @Override
        public List<ServiceConsumer<?>> getDependencies() {
                // ...
        }
}

Now I want the getDependencies() to return the other 2 (or more)
services and I want to be able to glue them outside the class
CustomerServiceConsumer .

@Thomas I think you MultiBinder is what I need but I'm using GIN and
it's not supported :(


Any other suggestions ?

Aladdin


On Dec 21 2011, 12:19 pm, Thomas Broyer <[email protected]> wrote:
> As others, I'm not sure I understood your problem, but maybe you're looking
> for the multibindings 
> extension<http://code.google.com/p/google-guice/wiki/Multibindings>
> :
>
> MultiBinder<ServiceConsumer> multi = Multibinder.newSetBinder(binder(),
> ServiceConsumer.class);
> multi.addBinding().to(CustomerAccountsServiceConsumer.class);
> multi.addBinding().to(CustomCreditCardsServiceConsumer.class);
>
> and then in CustomerServiceConsumer, @Inject a Set<ServiceConsumer> (and
> turn it into a List, using e.g. new ArrayList(set), to comply with your
> getDependencies return type).

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to