Soenneker.Blazor.Utils.InteropEventListener
4.0.4075
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.InteropEventListener --version 4.0.4075
NuGet\Install-Package Soenneker.Blazor.Utils.InteropEventListener -Version 4.0.4075
<PackageReference Include="Soenneker.Blazor.Utils.InteropEventListener" Version="4.0.4075" />
<PackageVersion Include="Soenneker.Blazor.Utils.InteropEventListener" Version="4.0.4075" />
<PackageReference Include="Soenneker.Blazor.Utils.InteropEventListener" />
paket add Soenneker.Blazor.Utils.InteropEventListener --version 4.0.4075
#r "nuget: Soenneker.Blazor.Utils.InteropEventListener, 4.0.4075"
#:package Soenneker.Blazor.Utils.InteropEventListener@4.0.4075
#addin nuget:?package=Soenneker.Blazor.Utils.InteropEventListener&version=4.0.4075
#tool nuget:?package=Soenneker.Blazor.Utils.InteropEventListener&version=4.0.4075
Soenneker.Blazor.Utils.InteropEventListener
Owns the DotNetObjectReference callbacks used by one Blazor JavaScript event-listening interop instance.
It creates callback wrappers for one-way and request/response events, suppresses duplicate registrations by element ID and event name, rolls back failed registrations, and disposes callback references during cleanup. JavaScript listener attachment and removal remain the consuming interop’s responsibility.
Installation
dotnet add package Soenneker.Blazor.Utils.InteropEventListener
Register a transient manager because each instance contains listener state and binds to one interop object:
using Soenneker.Blazor.Utils.InteropEventListener.Registrars;
builder.Services.AddInteropEventListenerAsTransient();
Inject IInteropEventListener into the component that owns the corresponding JavaScript widget or element.
Initialize and add a callback
Call Initialize once with an IEventListeningInterop implementation, then register callbacks after the element exists:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
EventListener.Initialize(WidgetInterop);
await EventListener.Add<WidgetChange>(
"widgetInterop.addEventListener",
_elementId,
"change",
change => HandleChange(change));
}
private ValueTask HandleChange(WidgetChange change)
{
// Validate browser-provided data before using it.
return ValueTask.CompletedTask;
}
The supplied interop receives the function name, element ID, event name, and a managed callback reference. Its JavaScript registration function must retain and invoke that reference using the method expected by the Soenneker Blazor invoker.
An instance cannot be rebound to a different interop object. Resolve a separate transient manager for each independent component or interop owner.
Callbacks that return a value
Use the two-type overload when JavaScript needs a result from .NET:
await EventListener.Add<ValidationRequest, ValidationResult>(
"widgetInterop.addValidator",
_elementId,
"validate",
request => Validate(request));
Registration identity is the ordinal pair (elementId, eventName). A second registration for the same pair is skipped and logged as a warning, even if its function name or callback differs.
If JavaScript registration throws or is cancelled, the newly created .NET reference is removed and disposed so the same pair can be retried.
Cleanup order
Remove and DisposeForElement release .NET callback references; they cannot remove a DOM listener because this package has no JavaScript removal-function contract.
Use this order when an element or widget is torn down:
await WidgetInterop.RemoveEventListener(_elementId, "change");
EventListener.Remove(_elementId, "change");
Or destroy the JavaScript widget so it can no longer invoke callbacks, then release every callback for the element:
await WidgetInterop.Destroy(_elementId);
EventListener.DisposeForElement(_elementId);
Never dispose a callback reference while JavaScript can still invoke it. Doing so leaves a live browser listener pointing at an invalid .NET object.
The DI container eventually disposes transient instances it created, but component cleanup should release JavaScript listeners and callback references as soon as their owner is removed. Cancellation only affects pending registration; it does not unregister a listener that JavaScript already attached.
Treat event payloads as untrusted browser input. Validate them before using them for authorization, file access, navigation, or other privileged behavior.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Blazor.Utils.BlazorInvoker (>= 4.0.1047)
- Soenneker.Blazor.Utils.BlazorOutputInvoker (>= 4.0.1017)
- Soenneker.Blazor.Utils.EventListeningInterop (>= 4.0.1140)
- Soenneker.Extensions.Object (>= 4.0.4302)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Soenneker.Blazor.Utils.InteropEventListener:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.TomSelect
A Blazor interop library for the select user control library, Tom Select |
|
|
Soenneker.Blazor.FilePond
A Blazor interop library for the file upload library FilePond |
|
|
Soenneker.Blazor.DataTables
A Blazor interop library for DataTables |
|
|
Soenneker.Blazor.Stripe.Elements
A modular, strongly-typed Blazor library for Stripe Elements |
|
|
Soenneker.Telnyx.Blazor.WebRtc
Blazor interop library for the Telnyx WebRTC client, providing full access to Telnyx's browser-based voice and video calling features. Includes typed wrappers, event bridging, and support for advanced call control in Blazor WebAssembly apps. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.4081 | 0 | 8/30/2026 |
| 4.0.4079 | 0 | 8/30/2026 |
| 4.0.4078 | 25 | 8/30/2026 |
| 4.0.4076 | 117 | 8/30/2026 |
| 4.0.4075 | 36 | 8/30/2026 |
| 4.0.4074 | 36 | 8/30/2026 |
| 4.0.4073 | 71 | 8/29/2026 |
| 4.0.4071 | 69 | 8/29/2026 |
| 4.0.4070 | 38 | 8/29/2026 |
| 4.0.4069 | 35 | 8/29/2026 |
| 4.0.4068 | 566 | 8/26/2026 |
| 4.0.4067 | 190 | 8/26/2026 |
| 4.0.4066 | 209 | 8/26/2026 |
| 4.0.4065 | 157 | 8/25/2026 |
| 4.0.4064 | 318 | 8/22/2026 |
| 4.0.4063 | 223 | 8/22/2026 |
| 4.0.4062 | 390 | 8/21/2026 |
| 4.0.4061 | 329 | 8/21/2026 |
| 4.0.4060 | 539 | 8/19/2026 |
| 4.0.4059 | 287 | 8/19/2026 |
Update dependency Soenneker.Blazor.Utils.BlazorOutputInvoker to 4.0.1017 (#4633)