I'm new to spring and I'm trying to refactor some code, I have the following "Session.class":
public class Session {
...
private Wallet currenetWallet;
...
public Session(..., int sessionId, ...) {
...
ThirdPartyToken token = context.getBean(ThirdPartyTokenDAO.class).getThirdPartyToken(sessionId);
if (token.getExternalUser().getMerchant().getType().equals("SOAPMerchant")) {
currenetWallet = (Wallet) context.getBean("SOAPExternalWallet", token);
}
else if (token.getExternalUser().getMerchant().getType().equals("JSONMerchant")) {
currenetWallet = (Wallet) context.getBean("JSONExternalWallet", token);
}
else {
currenetWallet = (Wallet) context.getBean("GuestWallet", 1000.0);
}
...
}
}
I read that using context.getBean() is a bad practice, and makes the class untestable. What would be the correct way of wiring the currentWallet according to the above?