Imagine the following constuctor
public RestClient(
string key,
Uri baseAddress,
IHttpClient httpClient,
ISerializer serializer,
IResponseFactory responseFactory)
{
_key = key;
_baseAddress = baseAddress;
_httpClient = httpClient;
_serializer = serializer;
_responseFactory = responseFactory;
}
When is it appropriate to create a local default like this?
public RestClient(
string key,
Uri baseAddress,
IHttpClient httpClient,
ISerializer serializer,
IResponseFactory responseFactory)
{
_key = key;
_baseAddress = baseAddress;
_serializer = serializer;
_responseFactory = responseFactory;
HttpClient = new HttpClientAdapter();
}
IHttpClient HttpClient {get; set;}
and allowing the dependency of IHttpClient to be overridden using property injection.
Or is it the responsibility of the consumer to pass the dependency in the constructor and not rely on local defaults at all? Mark Seemann, in his book describes that property injection is appropriate when there is a good local default but I am struggling in this example to decide whether or not it is appropriate to use a local default in the first place.