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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Blazor.Utils.EventListeningInterop" Version="4.0.1144" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.EventListeningInterop" Version="4.0.1144" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.EventListeningInterop" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Blazor.Utils.EventListeningInterop --version 4.0.1144
                    
#r "nuget: Soenneker.Blazor.Utils.EventListeningInterop, 4.0.1144"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Blazor.Utils.EventListeningInterop@4.0.1144
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Blazor.Utils.EventListeningInterop&version=4.0.1144
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.EventListeningInterop&version=4.0.1144
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 750 8/30/2026
4.0.1143 35 8/29/2026
4.0.1142 37 8/29/2026
4.0.1141 34 8/29/2026
4.0.1140 4,022 8/12/2026
4.0.1139 4,314 7/27/2026
4.0.1138 4,020 7/16/2026
4.0.1137 1,299 7/14/2026
4.0.1136 5,524 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,846 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
Loading failed

Clarify event listening interop contract