[Blazor] Consider providing circuits scoped values out of the box
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
It's currently hard to have information available "statically" in the context of a circuit. This is helpful when you need to deal with call sites, libraries, etc. where you can't provide the context and for services that create their own scope.
While adding these types of primitives introduces some risk of misuse, also solves a very common problem that our users face.
It is technically doable to do this today with a hub filter, by wrapping all calls to the Component hub methods and setting up an `AsyncLocal` variable with the right context, but it is incredibly complicated, savvy, and forces each developer to come up with their own implementation. (We also don't want people writing Hub filters for the component hub).
The idea here is to provide some primitive/abstraction to allow access to state for the circuit. It can be something like an `ICircuitContextAccessor` (similar to IHttpContextAccessor) or something more low level like a `static CircuitLocal` type that allows the value to be local to the circuit.
This will make it trivial to implement a handler for things like HttpClient when using HttpClientFactory to access state related to the circuit.
Related to https://github.com/dotnet/aspnetcore/issues/28684
Contributor guide
Research direction
Start by reading related issue #28684 and the Component hub methods mentioned here, then compare the existing hub-filter/AsyncLocal approach with the proposed abstraction. The issue names no files or tests; done means agreeing on and implementing a circuit-scoped state primitive that supports the stated call-site, library, and HttpClientFactory scenarios.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100