Skip to content

Commit 8ceffc1

Browse files
authored
Remove explicit using in HTTP examples (#46026)
* Remove explicit using in HTTP examples * Remove IDisposable impl
1 parent efbc580 commit 8ceffc1

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

docs/core/extensions/httpclient-factory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Use the IHttpClientFactory
33
description: Learn how to use the HttpClient and IHttpClientFactory implementations with dependency injection in your .NET workloads.
44
author: IEvangelist
55
ms.author: dapine
6-
ms.date: 08/13/2024
6+
ms.date: 05/06/2025
77
---
88

99
# IHttpClientFactory with .NET

docs/core/extensions/snippets/http/basic/TodoService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class TodoService(
1212
public async Task<Todo[]> GetUserTodosAsync(int userId)
1313
{
1414
// Create the client
15-
using HttpClient client = httpClientFactory.CreateClient();
15+
HttpClient client = httpClientFactory.CreateClient();
1616

1717
try
1818
{

docs/core/extensions/snippets/http/named/TodoService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task<Todo[]> GetUserTodosAsync(int userId)
2323
{
2424
// Create the client
2525
string? httpClientName = _configuration["TodoHttpClientName"];
26-
using HttpClient client = _httpClientFactory.CreateClient(httpClientName ?? "");
26+
HttpClient client = _httpClientFactory.CreateClient(httpClientName ?? "");
2727

2828
try
2929
{

docs/core/extensions/snippets/http/typed/TodoService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace TypedHttp.Example;
77

88
public sealed class TodoService(
99
HttpClient httpClient,
10-
ILogger<TodoService> logger) : IDisposable
10+
ILogger<TodoService> logger)
1111
{
1212
public async Task<Todo[]> GetUserTodosAsync(int userId)
1313
{
@@ -28,6 +28,4 @@ public async Task<Todo[]> GetUserTodosAsync(int userId)
2828

2929
return [];
3030
}
31-
32-
public void Dispose() => httpClient?.Dispose();
3331
}

0 commit comments

Comments
 (0)