File tree Expand file tree Collapse file tree 4 files changed +4
-6
lines changed Expand file tree Collapse file tree 4 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ title: Use the IHttpClientFactory
3
3
description : Learn how to use the HttpClient and IHttpClientFactory implementations with dependency injection in your .NET workloads.
4
4
author : IEvangelist
5
5
ms.author : dapine
6
- ms.date : 08/13/2024
6
+ ms.date : 05/06/2025
7
7
---
8
8
9
9
# IHttpClientFactory with .NET
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public sealed class TodoService(
12
12
public async Task < Todo [ ] > GetUserTodosAsync ( int userId )
13
13
{
14
14
// Create the client
15
- using HttpClient client = httpClientFactory . CreateClient ( ) ;
15
+ HttpClient client = httpClientFactory . CreateClient ( ) ;
16
16
17
17
try
18
18
{
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public async Task<Todo[]> GetUserTodosAsync(int userId)
23
23
{
24
24
// Create the client
25
25
string ? httpClientName = _configuration [ "TodoHttpClientName" ] ;
26
- using HttpClient client = _httpClientFactory . CreateClient ( httpClientName ?? "" ) ;
26
+ HttpClient client = _httpClientFactory . CreateClient ( httpClientName ?? "" ) ;
27
27
28
28
try
29
29
{
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ namespace TypedHttp.Example;
7
7
8
8
public sealed class TodoService (
9
9
HttpClient httpClient ,
10
- ILogger < TodoService > logger ) : IDisposable
10
+ ILogger < TodoService > logger )
11
11
{
12
12
public async Task < Todo [ ] > GetUserTodosAsync ( int userId )
13
13
{
@@ -28,6 +28,4 @@ public async Task<Todo[]> GetUserTodosAsync(int userId)
28
28
29
29
return [ ] ;
30
30
}
31
-
32
- public void Dispose ( ) => httpClient ? . Dispose ( ) ;
33
31
}
You can’t perform that action at this time.
0 commit comments