Soenneker.Blazor.Utils.BlazorOutputInvoker
4.0.1017
Prefix Reserved
dotnet add package Soenneker.Blazor.Utils.BlazorOutputInvoker --version 4.0.1017
NuGet\Install-Package Soenneker.Blazor.Utils.BlazorOutputInvoker -Version 4.0.1017
<PackageReference Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" Version="4.0.1017" />
<PackageVersion Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" Version="4.0.1017" />
<PackageReference Include="Soenneker.Blazor.Utils.BlazorOutputInvoker" />
paket add Soenneker.Blazor.Utils.BlazorOutputInvoker --version 4.0.1017
#r "nuget: Soenneker.Blazor.Utils.BlazorOutputInvoker, 4.0.1017"
#:package Soenneker.Blazor.Utils.BlazorOutputInvoker@4.0.1017
#addin nuget:?package=Soenneker.Blazor.Utils.BlazorOutputInvoker&version=4.0.1017
#tool nuget:?package=Soenneker.Blazor.Utils.BlazorOutputInvoker&version=4.0.1017
Soenneker.Blazor.Utils.BlazorOutputInvoker
An adapter that exposes a Func<TInput, ValueTask<TOutput>> as an instance [JSInvokable] method and returns the serialized result to JavaScript.
Installation
dotnet add package Soenneker.Blazor.Utils.BlazorOutputInvoker
There is no service registration. Construct the callback, retain a DotNetObjectReference, and pass it to the JavaScript code that owns the call site.
Usage
using Microsoft.JSInterop;
using Soenneker.Blazor.Utils.BlazorOutputInvoker;
var invoker = new BlazorOutputInvoker<NormalizeRequest, NormalizeResult>(request =>
ValueTask.FromResult(new NormalizeResult(request.Value.Trim(), request.Value.Length)));
DotNetObjectReference<BlazorOutputInvoker<NormalizeRequest, NormalizeResult>> reference =
DotNetObjectReference.Create(invoker);
await module.InvokeVoidAsync("registerNormalizeCallback", reference);
public sealed record NormalizeRequest(string Value);
public sealed record NormalizeResult(string Value, int OriginalLength);
JavaScript awaits InvokeWithOutput and receives a normal object:
let normalizeCallback;
export function registerNormalizeCallback(reference) {
normalizeCallback = reference;
}
export function unregisterNormalizeCallback() {
normalizeCallback = null;
}
export async function normalize(value) {
if (!normalizeCallback)
throw new Error("The normalize callback has not been registered.");
const result = await normalizeCallback.invokeMethodAsync("InvokeWithOutput", { value });
return result;
}
When the owner is disposed, unregister the browser callback before disposing the object reference:
await module.InvokeVoidAsync("unregisterNormalizeCallback");
reference.Dispose();
Contract and failure behavior
TInputandTOutputpass through Blazor's System.Text.Json-based interop serialization. Use serializable DTOs with predictable JSON names; delegates, streams, cyclic graphs, and arbitrary runtime objects are not suitable return values.- A nullable output is serialized as JavaScript
null. Model expected failures explicitly in the output DTO when JavaScript should handle them as normal results. - If the delegate throws, JavaScript's
invokeMethodAsyncpromise rejects. Await it and handle the error; do not expose internal exception details directly to end users. - The wrapper does not marshal onto a component renderer. A delegate that reads or changes component state should use the owning component's
InvokeAsync. - JavaScript cannot pass a .NET
CancellationTokento this method. Capture an appropriate lifetime token in the delegate if the work must stop during teardown. - The wrapper does not own the
DotNetObjectReference. Failing to unregister and dispose it keeps the delegate and captured services or component state alive. - Treat
TInputas untrusted browser input. Revalidate identity, authorization, identifiers, limits, and business rules before returning sensitive data or performing work.
This adapter is intended for a single request/response callback shape. Components with several distinct operations are usually clearer with named [JSInvokable] instance methods.
| 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.BlazorOutputInvoker:
| 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.1017 | 0 | 8/29/2026 |
| 4.0.1016 | 21 | 8/29/2026 |
| 4.0.1015 | 18 | 8/29/2026 |
| 4.0.1014 | 3,488 | 8/11/2026 |
| 4.0.1013 | 3,933 | 7/28/2026 |
| 4.0.1012 | 4,385 | 7/16/2026 |
| 4.0.1011 | 1,527 | 7/14/2026 |
| 4.0.1010 | 5,081 | 6/18/2026 |
| 4.0.1009 | 2,729 | 6/9/2026 |
| 4.0.1008 | 2,341 | 6/5/2026 |
| 4.0.1007 | 121 | 6/5/2026 |
| 4.0.1006 | 3,228 | 5/12/2026 |
| 4.0.1005 | 4,171 | 4/22/2026 |
| 4.0.1004 | 158 | 4/22/2026 |
| 4.0.1003 | 1,992 | 4/14/2026 |
| 4.0.1002 | 5,997 | 3/22/2026 |
| 4.0.1001 | 2,113 | 3/13/2026 |
| 4.0.1000 | 150 | 3/12/2026 |
| 4.0.999 | 144 | 3/12/2026 |
| 4.0.998 | 154 | 3/12/2026 |
Improve output invoker safety and README