Skip to content

Intercepting Blazor page events. #30115

@dotnetjunkie

Description

@dotnetjunkie

Blazor supports the notion of events, such as @onlick events, as shown here:

<button class="btn btn-danger" @onclick="DeleteUser">Delete</button>

This allows the DeleteUser method to be invoked in the page's @code section.

I'm looking for a mechanism that allows intercepting calls those 'code behind' methods, in order to be able to execute some infrastructure logic right before the method is invoked. If such mechanism is currently missing, I would urge the addition of a feature that makes this possible.

This question/discussion is related to my earlier issues #19642 and #29194 because I'm trying to find ways to integrate non-conforming DI Containers (such as Simple Injector) with the Blazor pipeline. As non-conforming containers don't replace the built-in DI Container, but merely live side-by-side, it is important to be able to start or continue a non-conforming container's Scope at the proper time.

Starting and continuing an existing scope can be done partially by:

  • intercepting the creation of Blazor components (using IComponentActivator) to start/continue a scope
  • intercepting the creation of SignalR hubs (using IHubActivator<T>) to start/continue a scope

This unfortunately leaves us with the invocation of Blazor events. When they are invoked, neither the IComponentActivator nor IHubActivator<T> is called, which causes that code to be executed outside the context of a non-conforming container's scope.

I might have overlooked the proper interception point for this in the Blazor code base. If there is such an interception point, please let me know. If there isn't, I would like to see it added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Blazor ♥ SignalRThis issue is related to the experience of Signal R and Blazor working togetheraffected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-circuit-lifecycleIssues to do with blazor server lifecycle eventsseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions