public class OrganizationServiceProvider {
private final OrganizationServiceImpl orgService;
private final OrgDeatilsServiceImpl orgDetailService;
@Inject
OrganizationServiceProvider(final OrganizationServiceImpl
orgService, final OrgDeatilsServiceImpl orgDetailService) {
this.orgService = orgService;
this.orgDetailService = orgDetailService;
}
public OrganizationService getServiceFor(/* you must pass the the
necessary input to decide which impl to choose */) {
// your code goes here. it must return either orgService or
orgDetailService
}
}
public class OrganizationsResource {
private final OrganizationServiceProvider osProvider;
@Inject
OrganizationsResource(final OrganizationServiceProvider osProvider) {
this.osProvider = osProvider;
}
// more code...
}
There is no special binding in the Guice module necessary since all
injections go to concrete classes.
Of course it would be nice to introduce an interface for
OrganizationServiceProvider and have an OrganizationServiceProviderImpl.
In this case you would need to bind the impl to the interface.
--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.