If I have a client defined as follows:-
public interface Client {
void send(String message);
}
And an implementation as follows:-
final class SocketClient {
private Integer port;
@Inject
SocketClient(Integer port) {
this.port = port;
}
@Override
public void send(String message) {
System.out.println("Sending message:- "+message+" to port "+port);
}
}
How would I use Guice to instantiate multiple instances of the SocketClient, each connecting to different ports?
The first solution that comes to mind is to create a
SocketClientFactoryinterface that looks likeand then get factory instances using the assisted injection extension.