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
The current method of DI in Razor Components is by decorating the target properties with TargetAttribute.
This is not the traditional method of injection using the constructor, and in addition, makes it uncertain for the compiler whether these fields are gonna be null.
When using null reference types of C# 8, the compiler will issue a warning for all those fields, marking them nullable (?), they will issue warnings in the UI side of the page, as Razor doesn't seem to support the null conditional operator (?. or ?[]).
One solution could be suppressing the warnings manually or on top of page, like:
But the only solution that worked for me was to disable #nullable manually in each Razor page with injected properties.
My suggestion is that you extend the Razor generator so that it generate non-parameterless constructors in the same signature as the base-class code-behind.
Hi,
The current method of DI in Razor Components is by decorating the target properties with
TargetAttribute
.This is not the traditional method of injection using the constructor, and in addition, makes it uncertain for the compiler whether these fields are gonna be null.
When using null reference types of C# 8, the compiler will issue a warning for all those fields, marking them nullable (
?
), they will issue warnings in the UI side of the page, as Razor doesn't seem to support the null conditional operator (?.
or?[]
).One solution could be suppressing the warnings manually or on top of page, like:
But the only solution that worked for me was to disable
#nullable
manually in each Razor page with injected properties.My suggestion is that you extend the Razor generator so that it generate non-parameterless constructors in the same signature as the base-class code-behind.
cc: @guardrex.
The text was updated successfully, but these errors were encountered: