Skip to content

Commit f4fb281

Browse files
authored
Update dependency injection instructions for Blazor (#36269)
1 parent 8e57f15 commit f4fb281

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

aspnetcore/blazor/fundamentals/dependency-injection.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how Blazor apps can inject services into components.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 11/12/2024
8+
ms.date: 10/27/2025
99
uid: blazor/fundamentals/dependency-injection
1010
---
1111
# ASP.NET Core Blazor dependency injection
@@ -554,23 +554,32 @@ Transient service registrations for <xref:System.Net.Http.IHttpClientFactory>/<x
554554

555555
Other instances of <xref:System.Net.Http.IHttpClientFactory>/<xref:System.Net.Http.HttpClient> are also discovered. These instances can also be ignored.
556556

557+
:::moniker-end
558+
559+
:::moniker range=">= aspnetcore-8.0"
560+
557561
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.
558562

559563
To activate the demonstration code and witness its operation:
560564

561565
* Uncomment the transient disposable lines in `Program.cs`.
562566

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:
564568

565569
```diff
566-
- else if (name != "TransientService")
567-
+ else
570+
- && (c.Name != "TransientService")
568571
```
569572

570573
* Run the sample app and navigate to the `TransientService` component at `/transient-service`.
571574

572575
:::moniker-end
573576

577+
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
578+
579+
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+
574583
## Use of an Entity Framework Core (EF Core) DbContext from DI
575584

576585
For more information, see <xref:blazor/blazor-ef-core>.

0 commit comments

Comments
 (0)