-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[API Proposal] Ability to monitor circuit activity #47325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
api-approved
API was approved in API review, it can be implemented
area-blazor
Includes: Blazor, Razor Components
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
API Approved! namespace Microsoft.AspNetCore.Components.Server.Circuits;
+public sealed class CircuitInboundActivityContext
+{
+ public Circuit Circuit { get; }
+}
public abstract CircuitHandler
{
+ public virtual Func<CircuitInboundActivityContext, Task> CreateInboundActivityHandler(Func<CircuitInboundActivityContext, Task> next) => next;
} |
10 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
area-blazor
Includes: Blazor, Razor Components
Background and Motivation
Note: This was implemented in #46968
In Blazor Server apps, it's sometimes desirable to access Blazor services from a non-Blazor DI scope. Examples:
We currently document a solution here. It involves wrapping each asynchronous entry point into Blazor component code and capturing the Blazor context's
IServiceProvider
in anAsyncLocal
. Blazor services can then be referenced via the async local if the async call stack originates from Blazor code.However, this approach has its limitations:
ComponentBase
implementationComponentBase
derivation implementing the wrapper methodsSeparately, another common ask is to detect circuit idleness in support of custom circuit eviction logic.
Both these problems can be solved by allowing customers to inject a sort of "middleware" that runs for all incoming circuit activity that causes application code to run.
Proposed API
Usage Examples
To utilize the feature, create a class that extends
CircuitHandler
(required) and implementsIHandleCircuitActivity
. Then, add the class as a service to the DI container.Here's an example showing how to make Blazor services accessible to non-Blazor scopes:
BlazorServiceCircuitHandler.cs
BlazorServiceAccessor.cs
Program.cs
Alternative Designs
We considered adding a new method to the
CircuitHandler
class, but that introduces unnecessary overhead when theHandleInboundActivityAsync()
is not overridden.We also thought about including information about what "type" of event is being handled, but we decided against it because it ties our internal implementation to the public API, restricting us from making drastic changes to the area.
Risks
No known risks. This feature is additive and shouldn't change the behavior of existing apps.
The text was updated successfully, but these errors were encountered: