You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/fundamentals/dependency-injection.md
+13-4Lines changed: 13 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how Blazor apps can inject services into components.
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 11/12/2024
8
+
ms.date: 10/27/2025
9
9
uid: blazor/fundamentals/dependency-injection
10
10
---
11
11
# ASP.NET Core Blazor dependency injection
@@ -554,23 +554,32 @@ Transient service registrations for <xref:System.Net.Http.IHttpClientFactory>/<x
554
554
555
555
Other instances of <xref:System.Net.Http.IHttpClientFactory>/<xref:System.Net.Http.HttpClient> are also discovered. These instances can also be ignored.
556
556
557
+
:::moniker-end
558
+
559
+
:::moniker range=">= aspnetcore-8.0"
560
+
557
561
The Blazor sample apps in the [Blazor samples GitHub repository](https://github.com/dotnet/blazor-samples/tree/main) ([how to download](xref:blazor/fundamentals/index#sample-apps)) demonstrate the code to detect transient disposables. However, the code is deactivated because the sample apps include <xref:System.Net.Http.IHttpClientFactory>/<xref:System.Net.Http.HttpClient> handlers.
558
562
559
563
To activate the demonstration code and witness its operation:
560
564
561
565
* Uncomment the transient disposable lines in `Program.cs`.
562
566
563
-
* Remove the conditional check in `NavLink.razor` that prevents the `TransientService` component from displaying in the app's navigation sidebar:
567
+
* Remove the conditional check in `NavMenu.razor` that prevents the `TransientService` component from displaying in the app's navigation sidebar:
564
568
565
569
```diff
566
-
- else if (name != "TransientService")
567
-
+ else
570
+
- && (c.Name != "TransientService")
568
571
```
569
572
570
573
* Run the sample app and navigate to the `TransientService` component at `/transient-service`.
The Blazor sample apps in the [Blazor samples GitHub repository](https://github.com/dotnet/blazor-samples/tree/main) ([how to download](xref:blazor/fundamentals/index#sample-apps)) demonstrate the code to detect transient disposables. Run the sample app and navigate to the `TransientService` component at `/transient-service`.
580
+
581
+
:::moniker-end
582
+
574
583
## Use of an Entity Framework Core (EF Core) DbContext from DI
575
584
576
585
For more information, see <xref:blazor/blazor-ef-core>.
0 commit comments