Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// 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