dependency injection - Java inject implementations from multiple modules using TypeLiteral -


i have issue multiple implementations of interface, or rather injecting them list. question direct follow question:

java inject implementation using typeliteral

so refer havilly examples , refer solutions.

i have interface:

public interface iimplementme {      public string getvalue(); }  

and have multiple implementations of iimplementme interface different modules of project binded:

register(iimplementme.class).annotatedwith(names.named("somename")).to(someimplementation.class); 

everything zipped list in module

private static class customtypeliteral extends typeliteral<list<iimplementme>> { } bind(new customtypeliteral()).toregistry(); 

and there 2 assumptions (that makes story different linked question)

  1. i not know implementations of iimplementme, in particular if singletons (i can force if needed)
  2. they binded in different modules not managed me directly (and don't want bind implementations myself)

similarly, want inject list of of them in @singleton class , call them whenever needed.

@singleton class someendpoint {     @inject     public someendpoint(final list<iimplementme> implementations){     ///     } } 

and question is: guaranteed guice pick implementations ? know won't available in constructor(the list empty) after list should refreshed understand guice. i'm concerned scenario implementations not singletons , not used anywhere else beside class injects list(someendpoint in example) (i'm worried they'll never initialized never added list).

one additional thought: i'm not using multibinder(i avoid if possible since don't want force other users use aswell, bit clearer if register @named implementation of iimplementme theirs modules).


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -