I am trying to learn dependency injection. By example I have the following simple web service client I wrote that talks to a to a web service.
public class UserWebServiceClient
{
private Client client;
public UserWebServiceClient(String username, String password)
{
ClientConfig clientConfig = new DefaultApacheHttpClientConfig();
this.client = ApacheHttpClient.create(clientConfig);
this.client.addFilter(new HTTPBasicAuthFilter(username, password));
}
private WebResource getWebResource()
{
WebResource resource = this.client.resource("http://mywebservice/.......");
return resource;
}
public void createUser(String s) throws StorageAPIException
{
getWebResource().post(...);
}
}
Is this a candidate for dependency injection? Should I be injecting the client?
I don't want to push the complexity of that up to the user. I think Im getting a bit confused about when to use DI.