Skip to content

Instantly share code, notes, and snippets.

@Pacane
Last active February 12, 2016 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pacane/d5076cf3cc5c12d13a26 to your computer and use it in GitHub Desktop.
Save Pacane/d5076cf3cc5c12d13a26 to your computer and use it in GitHub Desktop.
// add these bindings
install(new DefaultModule.Builder().tokenFormatter(RouteTokenFormatter.class).build());
bind(UserService.class).to(UserServiceImpl.class).asEagerSingleton();
public interface UserService {
String getUsername(int userId);
void saveUsername(int userId, String username);
Map<Integer, String> getUsers();
}
// Dummy implementation of a UserService
public class UserServiceImpl implements UserService {
private Map<Integer, String> usernames;
public UserServiceImpl() {
usernames = new HashMap<>();
usernames.put(1, "Arcbees");
usernames.put(2, "Joel");
usernames.put(3, "Olivier");
}
@Override
public String getUsername(int userId) {
return usernames.get(userId);
}
@Override
public void saveUsername(int userId, String username) {
usernames.put(userId, username);
}
@Override
public Map<Integer, String> getUsers() {
return usernames;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment