Skip to content

[Blazor] Consider providing circuits scoped values out of the box #46506

@javiercn

Description

@javiercn

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<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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-serverfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions