If you need a specific implementation and can determine which one you need, I would inject both concrete classes into OrganizationResource and not have to do anything fancy. On Feb 24, 2014 1:18 PM, "sreenivasu puppala" <[email protected]> wrote:
> First of all thanks very much Tim for responding and sorry for not giving > the detailed information. Coming straight to the point > > Iam working on webservices . Heres's the Flow > > GET http://localhost:8182/indi/provide/organizations/{ou} > > > OrganizationsResource > -------->OrganizationService------>OrganizationServiceImpl > > Iam binding OrganizationService with OrganizationServiceImpl and injecting > the OrganizationService in OrganizationsResource > > @Inject > public void setOrganizationService(OrganizationService orgService) { > this.orgService= orgService; > } > > > Its fine till here but i have two implementations for OrganizationService > --------->OrgDeatilsServiceImpl which does some other job > > Now i want to bind both OrganizationServiceImpl and OrgDeatilsServiceImpl > to OrganizationService > > Confusions: > > 1) What procedure i have to use in Guice to bind two implementaions? > 2) How exactly i can code in OrganizationsResource to dynamically decide > which implementation to call. > > > I would appreciate if you give a sample example for the above > requirement. > > > Many thanks again for the quick reply and awaiting your response on this > mail. > > > Thanks > Sreni > > > > > > > > > > > > > On Thursday, February 20, 2014 5:30:52 AM UTC, Tim Boudreau wrote: >> >> You can do things like this with Guice 4's ProvisionListener. I did that >> once, so that classes or packages could be annotated with a "namespace" >> that determined where properties they wanted injected would be loaded from, >> to allow some legacy code I was helping rearchitect code to migrate off of >> hard-coded paths to things and manually loading configuration. See this: >> http://j.mp/1dPIuGN >> >> That being said, I've kind of regretted adding that feature ever since :-) >> >> But I don't think you need anything so general or complex. >> >> It's not clear from your post what you want to switch on to decide which >> implementation to provide. You don't want to use @Named, but *something* >> has to choose which thing to inject. So, where does the information live, >> which is used to decide that? And does it change at runtime? >> >> If it doesn't change at runtime, just give yourself a command-line >> argument or whatever equivalent makes sense for what you're doing (your >> class names above suggest some kind of test mode, but I'm guessing). Have >> @ImplementedBy pointing to a mock implementation, and only install the >> module that binds the real implementation if that flag is not there (or is >> there, whatever you want). >> >> If it's something more fancy, I don't think anyone can help you without >> knowing what information should be used to decide what to inject, and what >> part of the application has it. If you know what that is, all you need to >> do is write a Provider that uses it. >> >> -Tim >> >> -- > 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. > -- 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.
