Created
June 5, 2018 08:36
-
-
Save christiannagel/84279d0b311be56d4058dd723a534d1a to your computer and use it in GitHub Desktop.
Injecting HttpClient from a typed client configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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