Interoply 0.1.1

dotnet add package Interoply --version 0.1.1
                    
NuGet\Install-Package Interoply -Version 0.1.1
                    
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="Interoply" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Interoply" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Interoply" />
                    
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 Interoply --version 0.1.1
                    
#r "nuget: Interoply, 0.1.1"
                    
#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 Interoply@0.1.1
                    
#: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=Interoply&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Interoply&version=0.1.1
                    
Install as a Cake Tool

Interoply

Interoply is a lightweight, extensible library that makes JavaScript interop in Blazor simple, intuitive, and plug-and-play.
It handles browser events like resize, scroll, visibility, and even custom DOM events — so you don't have to write any JavaScript.

Nuget Nuget .NET 7 .NET 8 .NET 9

✨ Features

  • ✅ Listen to native browser events (resize, scroll, visibilitychange, etc.)
  • 🔄 Register to custom DOM events on any element (Soming soon)
  • ✅ Extend functionality with C#-only base services (zero JS knowledge required)
  • ✅ Automatic cleanup & no JS interop errors during prerender
  • ✅ Supports Blazor Server and WebAssembly

📦 Installation

dotnet add package Interoply

🛠️ Getting Started

1. Register Interoply

builder.Services.AddInteroply();

2. Use in your component

@inject IInteroplyService Interoply

<p>Window width: @width px</p>

@code {
    private int width;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await Interoply.RegisterOnResizeListnerAsync(UpdateWidth);
        }
    }

    ValueTask UpdateWidth(int w)
    {
        width = w;
        StateHasChanged();
        return ValueTask.CompletedTask;
    }
}

🔌 Write your own service

Interoply provides a base service InteroplyServiceBase — you can write your own services entirely in C#:

public class ToastService : InteroplyServiceBase, IToastService
    {
        protected override string JsModulePath => "./toast.js";

        public ToastService(IJSRuntime jsRuntime)
            : base(jsRuntime)
        { }

        public async ValueTask ShowToastAsync(string message)
        {
            await InvokeVoidAsync("showAlert", message);
        }
    }

Note: You need to add the JavaScript file toast.js to your project under wwwroot folder with the following content:

export function showAlert(message) {
  return alert(message);
}

And register it like this:

builder.Services.AddInteroply();
builder.Services.AddScoped<IToastService, ToastService>();

⚙️ Supported Events

Event Method
Window Resize OnResizeAsync(Func<int, ValueTask>)
Scroll OnScrollAsync(Func<double, ValueTask>)
Visibility Change OnVisibilityChangeAsync(Func<bool, ValueTask>)
Online/Offline Status OnOnlineStatusChangeAsync(Func<bool, ValueTask>)
Custom DOM Events (Coming soon) OnDomEventAsync(elementId, eventName, callback)

💡 Why Interoply?

Blazor is powerful — but JavaScript interop can be painful. Interoply takes care of:

  • 🔄 Bridging between JS and C# automatically
  • 🧹 Cleanup to prevent memory leaks
  • 🔧 Extensibility via base services
  • 😌 Simplifying your codebase

📝 License

License © 2025 Mabrouk Mahdhi

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 216 7/2/2025
0.1.0 208 4/6/2025

Updated Dependency Injection Packages to 9.0.6