Can I call cascading parameters and/or injected services anywhere?

David Thielen 3,211 Reputation points
2023-05-05T13:25:00.46+00:00

This seems to work but it may be because of where/how I'm using it (server side). In a random .cs file, not part of a page.razor.cs or similar file, I have the following:

[Inject] private ILogger<Register> Logger { get; set; } = default!;

[CascadingParameter] private Task<AuthenticationState> authenticationStateTask { get; set; } = default!;

and it works fine - I can use both. Is this valid to do in any code anywhere in the app once main() in program.cs has completed setup? Or is this something that will cause me problems and/or is limited to only certain uses?

thanks - dave

Developer technologies | .NET | Blazor
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.