Soenneker.Blazor.Utils.InteropEventListener 4.0.4075

Prefix Reserved
There is a newer version of this package available.
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
                    
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.InteropEventListener" Version="4.0.4075" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Utils.InteropEventListener" Version="4.0.4075" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Utils.InteropEventListener" />
                    
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.InteropEventListener --version 4.0.4075
                    
#r "nuget: Soenneker.Blazor.Utils.InteropEventListener, 4.0.4075"
                    
#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.InteropEventListener@4.0.4075
                    
#: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.InteropEventListener&version=4.0.4075
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Utils.InteropEventListener&version=4.0.4075
                    
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.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 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 (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.4078 0 8/30/2026
4.0.4076 0 8/30/2026
4.0.4075 0 8/30/2026
4.0.4074 0 8/30/2026
4.0.4073 0 8/29/2026
4.0.4071 27 8/29/2026
4.0.4070 28 8/29/2026
4.0.4069 26 8/29/2026
4.0.4068 368 8/26/2026
4.0.4067 183 8/26/2026
4.0.4066 202 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 328 8/21/2026
4.0.4060 539 8/19/2026
4.0.4059 287 8/19/2026
4.0.4058 317 8/18/2026
4.0.4057 221 8/18/2026
Loading failed

Update dependency Soenneker.Blazor.Utils.BlazorOutputInvoker to 4.0.1017 (#4633)