[Blazor] Server security - Inject AuthenticationStateProvider for ser… #34054
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This entire section seems more confusing than helpful:
What exactly do we mean by "custom scope" here? The article is focused on server-side Blazor, where the default scope is the circuit. Any additional scope, such as
OwningComponentBase, is simply a nested scope and will resolve the correctAuthenticationStateProviderinstance.Yes, we could construct an edge case - like using a
BackgroundServicein the same process, where there is no circuit scope available. But in such scenarios, there's no user identity available for that service workload anyway, and passing anAuthenticationStateProviderfrom a component to a background service method doesn't make sense.Firstly, the service itself is stateless (i.e., it has no instance data fields), which makes the choice of lifetime irrelevant.
Secondly, if both the service and
AuthenticationStateProviderhave lifetimes tied to the client connection circuit, why are we passingAuthenticationStateProvideras a method parameter? It seems unnecessary if they share the same scope.Thirdly, in the example below (
InjectAuthStateProvider.razor), a component scope is used to resolveExampleService, which contradicts the earlier statements about circuit-scoped services.Overall, this section introduces too much confusion and should probably be removed. The basic principles of scoped services and
OwningComponentBaseare already well-explained in the Dependency Injection documentation, and they apply just as well toAuthenticationStateProvider.If there's a specific behavior of
AuthenticationStateProviderthat needs to be covered here, we should rewrite the section with clear examples that illustrate this behavior effectively.Internal previews