[Blazor] Consider providing circuits scoped values out of the box #46506
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-blazor-server
feature-blazor-wasm
This issue is related to and / or impacts Blazor WebAssembly
Milestone
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 astatic CircuitLocal<T>
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 #28684
The text was updated successfully, but these errors were encountered: