Hi Group,

           Need a suggestion for how to code for multiple implementations 
for a service using Google-guice. Below is the example


           TestService testService =new TestServiceImplOne();
           TestService testService =new TestServiceImplTwo();


           As Guice doesn't allow to bind a type to more than one 
implementations as the below code results in error 

           binderObject.bind(SomeType.class).to(ImplemenationOne.class); 
           binderObject.bind(SomeType.class).to(ImplemenationTwo.class); 

           we can solve this with named annotations as below

           
binder.bind(Player.class).annotatedWith(Names.named("Good")).to(GoodPlayer.class);
 

           
binder.bind(Player.class).annotatedWith(Names.named("Bad")).to(BadPlayer.class);
 


          @Named("Good") Player goodPlayer = 
(Player)injector.getInstance(Player.class);
          @Named("Bad") Player badPlayer = 
(Player)injector.getInstance(Player.class);


           But the application which iam working is something like this


           we are binding all the modules in the init() method and creating 
the injector modules 
           
           //sepertae method to bind
           protected void configure() {
                    bind(new TypeLiteral<List<Service>>() {
                    }).toInstance(serviceSets);
                }

           //seperate method to inject
           Injector i = Guice.createInjector(modules);  //


        But with the above process I can just bind one Implementation class 
to the interface(service class)


        Could you please provice me a way to do this with providers. I 
would like to do something like this below

        class  TestServiceProvider extends Provider{

           /// some code where it returns the  instance of impl class 
needed. In my case TestServiceImplOne and TestServiceImplTwo and provider 
returns the corresponding instance of service class

        }

     
      and bind service class with provider class. Something like this

      bind(TestService.class).toProvider(TestServiceProvider.class); 

      May be iam talking something baseless , iam sorry if iam doing that 
but this is my requirement, i would  appreciate if someone suggest me a 
good example using providers or some other way where i can inject whatever 
implementation i want in the client.


      *Note*: Iam using webservices and iam absolutley not sure how i can 
inject different implementations when a webservice is called to a 
serviceclass .


    Thanks very much
    Sreenivasu
      








           




           

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to