Soenneker.Blazor.Utils.BlazorInvoker
4.0.1072
Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.BlazorInvoker --version 4.0.1072
NuGet\Install-Package Soenneker.Blazor.Utils.BlazorInvoker -Version 4.0.1072
<PackageReference Include="Soenneker.Blazor.Utils.BlazorInvoker" Version="4.0.1072" />
<PackageVersion Include="Soenneker.Blazor.Utils.BlazorInvoker" Version="4.0.1072" />
<PackageReference Include="Soenneker.Blazor.Utils.BlazorInvoker" />
paket add Soenneker.Blazor.Utils.BlazorInvoker --version 4.0.1072
#r "nuget: Soenneker.Blazor.Utils.BlazorInvoker, 4.0.1072"
#:package Soenneker.Blazor.Utils.BlazorInvoker@4.0.1072
#addin nuget:?package=Soenneker.Blazor.Utils.BlazorInvoker&version=4.0.1072
#tool nuget:?package=Soenneker.Blazor.Utils.BlazorInvoker&version=4.0.1072
Soenneker.Blazor.Utils.BlazorInvoker
A small adapter that exposes a Func<TInput, ValueTask> as an instance [JSInvokable] method for JavaScript-to-.NET callbacks.
Installation
dotnet add package Soenneker.Blazor.Utils.BlazorInvoker
There is no service registration. Create an invoker for a specific callback, wrap it in a DotNetObjectReference, and pass that reference to your JavaScript module.
Component example
@using Microsoft.JSInterop
@using Soenneker.Blazor.Utils.BlazorInvoker
@implements IAsyncDisposable
@inject IJSRuntime JS
<p>@_message</p>
@code {
private IJSObjectReference? _module;
private BlazorInvoker<BrowserMessage>? _invoker;
private DotNetObjectReference<BlazorInvoker<BrowserMessage>>? _reference;
private string? _message;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
_invoker = new BlazorInvoker<BrowserMessage>(message =>
new ValueTask(InvokeAsync(() =>
{
_message = message.Text;
StateHasChanged();
})));
_reference = DotNetObjectReference.Create(_invoker);
_module = await JS.InvokeAsync<IJSObjectReference>("import", "./callback.js");
await _module.InvokeVoidAsync("registerCallback", _reference);
}
public async ValueTask DisposeAsync()
{
if (_module is not null)
{
await _module.InvokeVoidAsync("unregisterCallback");
await _module.DisposeAsync();
}
_reference?.Dispose();
}
private sealed record BrowserMessage(string Text);
}
The JavaScript side receives the object reference and invokes its Invoke method:
let callback;
export function registerCallback(reference) {
callback = reference;
}
export function unregisterCallback() {
callback = null;
}
export async function publish(text) {
if (!callback)
throw new Error("The .NET callback has not been registered.");
await callback.invokeMethodAsync("Invoke", { text });
}
Behavior and ownership
Invoke(args)awaits the configured delegate. A delegate exception rejects JavaScript'sinvokeMethodAsyncpromise, so JavaScript callers should await and handle failures.- The invoker does not marshal work onto a component renderer. Use the owning component's
InvokeAsyncwhen the delegate changes component state or callsStateHasChanged. - JavaScript cannot supply a .NET
CancellationTokento this method. Capture a component or operation token in the delegate when cancellation is required. - The invoker does not create or dispose
DotNetObjectReference. The owner must retain and dispose that reference, or the delegate and any captured component state remain rooted. - A disposed object reference must not be invoked again. Unregister browser listeners before disposal when they can race with component teardown.
- Treat callback payloads as untrusted input. Validate values, sizes, identifiers, and authorization before using them in privileged operations.
BlazorInvoker<TInput> is useful when several interop wrappers need the same one-argument callback shape. For a component with multiple named callbacks, ordinary [JSInvokable] instance methods may be clearer.
| 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.13)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.BlazorInvoker:
| 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.1072 | 0 | 10/14/2026 |
| 4.0.1071 | 33 | 10/14/2026 |
| 4.0.1070 | 32 | 10/14/2026 |
| 4.0.1065 | 136 | 10/12/2026 |
| 4.0.1064 | 139 | 10/12/2026 |
| 4.0.1063 | 559 | 10/11/2026 |
| 4.0.1062 | 1,467 | 10/3/2026 |
| 4.0.1061 | 2,482 | 9/24/2026 |
| 4.0.1060 | 566 | 9/24/2026 |
| 4.0.1059 | 1,324 | 9/15/2026 |
| 4.0.1058 | 110 | 9/15/2026 |
| 4.0.1057 | 2,229 | 9/12/2026 |
| 4.0.1056 | 322 | 9/12/2026 |
| 4.0.1055 | 1,950 | 9/8/2026 |
| 4.0.1054 | 1,400 | 9/7/2026 |
| 4.0.1053 | 4,608 | 8/30/2026 |
| 4.0.1052 | 344 | 8/30/2026 |
| 4.0.1051 | 106 | 8/29/2026 |
| 4.0.1050 | 112 | 8/29/2026 |
| 4.0.1049 | 109 | 8/29/2026 |
Update dependency dotnet-sdk to v10.0.402 (#1658)
Automatically merged