Implement Dependency Injection for HttpClient

This commit is contained in:
Ross Healy
2024-02-03 23:50:03 +00:00
parent c4dc67241f
commit 36e89c8ae0
2 changed files with 4 additions and 5 deletions

View File

@@ -7,10 +7,8 @@ namespace lottery_co_uk_scraper
{ {
internal class Lotto internal class Lotto
{ {
public static async Task GetLottoNumbers(string url) public static async Task GetLottoNumbers(string url, HttpClient client)
{ {
using HttpClient client = new();
try try
{ {
string html = await client.GetStringAsync(url); string html = await client.GetStringAsync(url);

View File

@@ -4,9 +4,10 @@
{ {
static async Task Main() static async Task Main()
{ {
string url = "https://www.lottery.co.uk/lotto/results-22-07-2023"; using HttpClient client = new();
string url = "your_lottery_url_here";
await Lotto.GetLottoNumbers(url); await Lotto.GetLottoNumbers(url, client);
} }
} }
} }