From 9568d179f1cacafd0ab2e0e8b066c138b9eaa44c Mon Sep 17 00:00:00 2001 From: Robert Haken Date: Thu, 5 Sep 2024 16:26:31 +0200 Subject: [PATCH] [Blazor] Constructor injection updates (#33536) --- aspnetcore/blazor/fundamentals/dependency-injection.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/aspnetcore/blazor/fundamentals/dependency-injection.md b/aspnetcore/blazor/fundamentals/dependency-injection.md index ec3977fe68..1d9200c8a4 100644 --- a/aspnetcore/blazor/fundamentals/dependency-injection.md +++ b/aspnetcore/blazor/fundamentals/dependency-injection.md @@ -224,7 +224,7 @@ After services are added to the service collection, inject one or more services ```razor @page "/constructor-injection" - ``` @@ -236,7 +236,10 @@ using Microsoft.AspNetCore.Components; public partial class ConstructorInjection(NavigationManager navigation) { - protected NavigationManager Navigation { get; } = navigation; + private void HandleClick() + { + navigation.NavigateTo("/counter"); + } } ``` @@ -616,7 +619,7 @@ There may be times when a Razor component invokes asynchronous methods that exec For example, instances created using have their own DI service scope. As a result, instances configured on the aren't able to directly inject Blazor services. -Create a class `BlazorServiceAccessor` that defines an [`AsyncLocal`](xref:System.Threading.AsyncLocal`1), which stores the Blazor for the current asynchronous context. A `BlazorServiceAcccessor` instance can be acquired from within a different DI service scope to access Blazor services. +Create a class `BlazorServiceAccessor` that defines an [`AsyncLocal`](xref:System.Threading.AsyncLocal`1), which stores the Blazor for the current asynchronous context. A `BlazorServiceAccessor` instance can be acquired from within a different DI service scope to access Blazor services. `BlazorServiceAccessor.cs`: @@ -769,6 +772,7 @@ services.AddScoped(); * * [`IDisposable` guidance for Transient and shared instances](xref:fundamentals/dependency-injection#idisposable-guidance-for-transient-and-shared-instances) * +* [Primary constructors (C# Guide)](/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors#primary-constructors) :::moniker-end