Bootsharp 0.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Bootsharp --version 0.6.0
                    
NuGet\Install-Package Bootsharp -Version 0.6.0
                    
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="Bootsharp" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bootsharp" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="Bootsharp" />
                    
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 Bootsharp --version 0.6.0
                    
#r "nuget: Bootsharp, 0.6.0"
                    
#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.
#addin nuget:?package=Bootsharp&version=0.6.0
                    
Install Bootsharp as a Cake Addin
#tool nuget:?package=Bootsharp&version=0.6.0
                    
Install Bootsharp as a Cake Tool

<p align="center"> <a href="https://sharp.elringus.com" target="_blank" rel="noopener noreferrer"> <img width="200" src="https://raw.githubusercontent.com/elringus/bootsharp/main/docs/public/favicon.svg" alt="Bootsharp"> </a> </p> <br/> <p align="center"> <a href="https://www.nuget.org/packages/Bootsharp"><img src="https://img.shields.io/nuget/v/Bootsharp" alt="nuget"></a> <a href="https://codefactor.io/repository/github/elringus/bootsharp/overview/main"><img src="https://codefactor.io/repository/github/elringus/bootsharp/badge/main" alt="codefactor"></a> <a href="https://codecov.io/gh/elringus/bootsharp"><img src="https://codecov.io/gh/elringus/bootsharp/branch/main/graph/badge.svg?token=AAhei51ETt" alt="codecov"></a> <a href="https://github.com/elringus/bootsharp/actions/workflows/codeql.yml"><img src="https://github.com/elringus/bootsharp/actions/workflows/codeql.yml/badge.svg" alt="codeql"></a> </p> <br/>

Use C# in web apps with comfort

Bootsharp streamlines consuming .NET C# apps and libraries in web projects. It's ideal for building web applications, where domain (backend) is authored in .NET C#, while the UI (frontend) is a standalone TypeScript or JavaScript project. Think of it as Embind for C++ or wasm-bindgen for Rust.

alternate text is missing from this package README image

Features

✨ High-level C# ↔ TypeScript interop

📦 Embeds binaries to single-file ES module

🗺️ Works in browsers and JS runtimes (Node, Deno, Bun)

⚡ Generates bindings and types over C# interfaces

🏷️ Supports interop over object instances

🛠️ Allows customizing emitted bindings

🔥 Supports WASM multi-threading, AOT, trimming

🎬 Get Started

https://sharp.elringus.com/guide/getting-started

Why not Blazor?

In contrast to solutions like Blazor, which attempt to bring the entire web platform inside .NET, Bootsharp facilitates high-level interoperation between C# and TypeScript, allowing to build the UI layer under its natural ecosystem using industry-standard tooling and frameworks, such as React and Svelte.

Why not System.JavaScript?

Bootsharp itself is built on top of System.Runtime.InteropServices.JavaScript introduced in .NET 7.

If you need to expose a simple library API to JavaScript and don't require type declarations, Bootsharp is probably overkill. However, .NET's interop is low-level, lacks support for passing custom types by value, and requires extensive boilerplate to define bindings, making it impractical for large API surfaces.

With Bootsharp, you can simply provide your domain-specific interfaces and use them seamlessly on the other side, as if they were originally authored in TypeScript (and vice versa). This ensures a clear separation of concerns: your domain codebase won't be aware of the JavaScript environment—no need to annotate methods for interop or specify marshalling hints for arguments.

For example, consider the following abstract domain code:

public record Data (string Info, IReadOnlyList<Item> Items);
public record Result (View Header, View Content);
public interface IProvider { Data GetData (); }
public interface IGenerator { Result Generate (); }

public class Generator (IProvider provider) : IGenerator
{
    public Result Generate ()
    {
        var data = provider.GetData();
        // Process the data and generate result.
        return result;
    }
}

— the code doesn't use any JavaScript-specific APIs, making it fully testable and reusable. To expose it to JavaScript, all we need to do is add the following to Program.cs in a separate project for the WASM target:

using Bootsharp;
using Bootsharp.Inject;
using Microsoft.Extensions.DependencyInjection;

[assembly: JSImport(typeof(IProvider))]
[assembly: JSExport(typeof(IGenerator))]

// Bootsharp auto-injects implementation for 'IProvider'
// from JS and exposes 'Generator' APIs to JS.
new ServiceCollection()
    .AddBootsharp()
    .AddSingleton<IGenerator, Generator>()
    .BuildServiceProvider()
    .RunBootsharp();

— we can now provide implementation for IProvider and use Generator in JavaScript/TypeScript:

import bootsharp, { Provider, Generator } from "bootsharp";

// Implement 'IProvider'.
Provider.getData = () => ({
    info: "...",
    items: []
});

await bootsharp.boot();

// Use 'Generator'.
const result = Generator.generate();
Product Compatible and additional computed target framework versions.
.NET 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. 
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 (1)

Showing the top 1 popular GitHub repositories that depend on Bootsharp:

Repository Stars
elringus/bootsharp
Use C# in web apps with comfort
Version Downloads Last updated
0.6.1 52 3 days ago
0.6.0 152 9 days ago
0.5.0 79 10 days ago
0.4.0 180 3 months ago
0.3.3 954 7 months ago
0.3.2 1,362 5/28/2024
0.3.1 800 2/7/2024
0.3.0 136 2/5/2024
0.2.0 519 1/23/2024
0.1.3 269 1/6/2024
0.1.2 157 1/5/2024
0.1.1 169 1/1/2024
0.1.0 158 12/31/2023