Hi Martin, Thanks for the reply.
Could I trouble you for a minimal example of what that provider might look like? Cheers, tew88 On 8 Sep 2014 22:55, "Martin Grajcar" <[email protected]> wrote: > I had a similar. Just > > bind(NetworkCommunicator.class) > .toProvider(NetworkCommunicator.class); > > Inject all needed information into your provider and let it take the > decision. > > On Mon, Sep 8, 2014 at 10:51 PM, tew88 <[email protected]> wrote: > >> Hi, >> >> An approximation of my problem as follows: >> >> Based upon a value that I will parse from an incoming request, I wish to >> inject one of two implementations of my interface. Where is this logic >> best placed? >> >> More specifically: >> >> public interface NetworkCommunicator { >> public void sendCommandToNetwork(Command command, NetworkElement >> recipient); >> } >> >> -- >> >> public class OldNetworkCommunicatorImpl implements NetworkCommunicator { >> @Override >> public void sendCommandToNetwork(Command command, NetworkElement >> recipient) { >> ... >> } >> } >> >> -- >> >> public class NewNetworkCommunicatorImpl implements NetworkCommunicator { >> @Override >> public void sendCommandToNetwork(Command command, NetworkElement >> recipient) { >> ... >> } >> } >> >> -- >> >> public class NetworkCommandIssuer { >> >> private final NetworkCommunicator networkCommunicator; >> >> @Inject >> public NetworkCommandIssuer(final NetworkCommunicator >> networkCommunicator) { >> this.networkCommunicator = networkCommunicator; >> } >> } >> >> -- >> >> Based on some arbitrary mapping, I'd like to wire up my >> NetworkCommandIssuer to use my NewNetworkCommunicatorImpl implementation >> instead of my OldNetworkCommunicatorImpl implementation. This will change >> from request to request. So, where should I define this behaviour? >> >> I'm new to Guice and DI in general, so please assume as little as >> possible in your responses! >> >> Thanks in advance, >> tew88 >> >> -- >> 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. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/google-guice/1122d17f-b029-4c04-be4c-2b6ba6485295%40googlegroups.com >> <https://groups.google.com/d/msgid/google-guice/1122d17f-b029-4c04-be4c-2b6ba6485295%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "google-guice" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/google-guice/WtZjeFPp2b8/unsubscribe. > To unsubscribe from this group and all its topics, 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/CAGsWfGjkUw%2BhR6Sr8b-9RHHyLXW-ZEUDxRZQ3PgpfXNw_Wyr1w%40mail.gmail.com > <https://groups.google.com/d/msgid/google-guice/CAGsWfGjkUw%2BhR6Sr8b-9RHHyLXW-ZEUDxRZQ3PgpfXNw_Wyr1w%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAAuuRUadUThcJ0u%2BRDLwQ2cBvYeECSuu0307opJQNsOAR9OJRw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
