Soenneker.Blazor.Utils.EventListeningInterop
4.0.1144
Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.EventListeningInterop --version 4.0.1144
NuGet\Install-Package Soenneker.Blazor.Utils.EventListeningInterop -Version 4.0.1144
<PackageReference Include="Soenneker.Blazor.Utils.EventListeningInterop" Version="4.0.1144" />
<PackageVersion Include="Soenneker.Blazor.Utils.EventListeningInterop" Version="4.0.1144" />
<PackageReference Include="Soenneker.Blazor.Utils.EventListeningInterop" />
paket add Soenneker.Blazor.Utils.EventListeningInterop --version 4.0.1144
#r "nuget: Soenneker.Blazor.Utils.EventListeningInterop, 4.0.1144"
#:package Soenneker.Blazor.Utils.EventListeningInterop@4.0.1144
#addin nuget:?package=Soenneker.Blazor.Utils.EventListeningInterop&version=4.0.1144
#tool nuget:?package=Soenneker.Blazor.Utils.EventListeningInterop&version=4.0.1144
Soenneker.Blazor.Utils.EventListeningInterop
A small base contract for Blazor interop classes that delegate DOM event-listener registration to JavaScript.
This is infrastructure for library authors, not a standalone event-listener service. It standardizes the call shape used by higher-level packages such as Soenneker.Blazor.Utils.InteropEventListener.
Installation
dotnet add package Soenneker.Blazor.Utils.EventListeningInterop
No DI registrar is included. Derive an interop class from EventListeningInterop, or implement IEventListeningInterop when listener registration happens through an imported JavaScript module.
Derive from the base class
The base implementation calls a JavaScript function through IJSRuntime with these arguments, in order: element ID, event name, and callback object.
using Microsoft.JSInterop;
using Soenneker.Blazor.Utils.EventListeningInterop;
public sealed class WidgetInterop : EventListeningInterop
{
public WidgetInterop(IJSRuntime jsRuntime) : base(jsRuntime)
{
}
public ValueTask Listen(
string elementId,
string eventName,
object callback,
CancellationToken cancellationToken = default)
{
return AddEventListener(
"widgetInterop.addEventListener",
elementId,
eventName,
callback,
cancellationToken);
}
}
The corresponding JavaScript function must accept that shape:
window.widgetInterop = {
addEventListener(elementId, eventName, callback) {
const element = document.getElementById(elementId);
if (!element)
throw new Error(`Element '${elementId}' was not found.`);
element.addEventListener(eventName, event => {
callback.invokeMethodAsync("Invoke", event.type);
});
}
};
If your JavaScript lives in an imported ES module, implement IEventListeningInterop and invoke the function on the module reference instead of using the base class, because the base class resolves a global IJSRuntime identifier.
Listener and callback lifetime
AddEventListener only waits for the JavaScript registration call. Cancelling its token can cancel that pending interop call; it does not remove a listener that JavaScript already attached.
The consuming interop must define a matching JavaScript removal operation and call it during component or service disposal. It must also keep any DotNetObjectReference<T> alive for as long as JavaScript can invoke it, then dispose the reference only after the listener can no longer fire. Adding the same listener more than once is not deduplicated here.
Treat functionName as a trusted constant owned by the library. Do not accept it from URL, markup, or other untrusted input. Callback payloads originate in the browser and should be validated before they affect privileged application 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
- Microsoft.JSInterop (>= 10.0.11)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.EventListeningInterop:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.Utils.InteropEventListener
Manages the registration, removal, and disposal of .NET object references used for interop event listeners. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1144 | 1,018 | 8/30/2026 |
| 4.0.1143 | 44 | 8/29/2026 |
| 4.0.1142 | 45 | 8/29/2026 |
| 4.0.1141 | 42 | 8/29/2026 |
| 4.0.1140 | 4,042 | 8/12/2026 |
| 4.0.1139 | 4,315 | 7/27/2026 |
| 4.0.1138 | 4,020 | 7/16/2026 |
| 4.0.1137 | 1,299 | 7/14/2026 |
| 4.0.1136 | 5,536 | 6/18/2026 |
| 4.0.1135 | 3,290 | 6/9/2026 |
| 4.0.1134 | 2,304 | 6/5/2026 |
| 4.0.1133 | 3,117 | 5/12/2026 |
| 4.0.1132 | 4,061 | 4/22/2026 |
| 4.0.1131 | 114 | 4/21/2026 |
| 4.0.1130 | 2,185 | 4/14/2026 |
| 4.0.1129 | 5,863 | 3/22/2026 |
| 4.0.1128 | 2,259 | 3/12/2026 |
| 4.0.1127 | 124 | 3/12/2026 |
| 4.0.1126 | 125 | 3/12/2026 |
| 4.0.1125 | 126 | 3/12/2026 |
Clarify event listening interop contract