Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

.NET 8 & Blazor components nullable warning with @ref

$
0
0

From what I understand the recommended method to hide null warnings on services is the following:

[Inject] private IExampleService ExampleService { get; set; } = default!;

https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-6.0#request-a-service-in-a-component

I'm wondering if the same applies to components that are given a reference in code behind with the @ref notation or if this should be handled differently?

For example using DevExpress components:

<DxButton Text="Button" @ref=ExampleButton />@code {    private DxButton ExampleButton { get; set; }  = default!;}

If I understand this correctly the renderer populates the ExampleButton property after rendering so null exceptions are possible if the property is used in an OnInitialized() method therefor I am unsure if !default is the correct approach.

I was hoping DevExpress themselves would have some documentation about this, however I was unable to find anything.


Viewing all articles
Browse latest Browse all 4839

Trending Articles