I am somewhat familiar with Guice and am reading the wiki, but I have a question.Let's say I have a Person class, with a constructor that takes a name. How can I use a Guice module to create 2 instance, one with "Rob" and one with "Sara"? Are there different approaches? What are the implications, pros and cons of each approach?Thanks,--
Rob
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/vNoxnL6YbtcJ.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Hi Olivier,
I am still having trouble understanding how to contextualize a module with some data, whether value objects or not. Here is my attempt (I am a long way from being able to test it):
public class MurmurModule extends AbstractModule {
private final WhisperIdentity serverId;
public MurmurModule(String nickname, String hostname, Integer port) {
TcpIdentity tcpId = new TcpIdentity(hostname, port);
this.serverId = new WhisperIdentity(nickname, tcpId);
}
@Override
protected void configure() {
bind(WhisperIdentity.class).toInstance(serverId);
bind(SwissTable.class);
bind(MurmurServer.class);
bind(MurmurTerminal.class);
}
}
So I pass in the context by values, build an instance of a non-value class, and bind to that instance within the scope of this module. I can instantiate more than one module. When I build an injector from each instance of the module, that injector gets appropriately contextualized. Is the the best way to go? Are there other good ways to go, perhaps with Guice properties or something?
Regarding AssistedInject, from the wiki page, how does the Date and Money get passed in? It is the same problem, but one layer of indirection over, isn’t it?
Thanks,
Rob