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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to