Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created June 5, 2018 08:36
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 christiannagel/84279d0b311be56d4058dd723a534d1a to your computer and use it in GitHub Desktop.
Save christiannagel/84279d0b311be56d4058dd723a534d1a to your computer and use it in GitHub Desktop.
Injecting HttpClient from a typed client configuration
class TypedClient
{
private readonly HttpClient _httpClient;
public TypedClient(HttpClient httpClient)
{
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
}
public async Task CallServerAsync()
{
var response = await _httpClient.GetAsync("/downloads/Racers.xml");
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment