WACS.WASI.Preview2.DependencyInjection 0.2.2

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

WACS.WASI.Preview2.DependencyInjection

Microsoft.Extensions.DependencyInjection extensions for WACS.WASI.Preview2. One-call registration of every WASI 0.2.3 subsystem default + a pre-wired Linker.

Component-mode WASI Preview 2 hosts assemble a lot of moving pieces — typed [WitSource] interfaces per subsystem, the resource-handle registry, the Linker that fires every *Bindings.BindToRuntime, the composite bundle that exposes Preview 2 + WASI.NN through one CLR object. This package wires it all in idiomatic .NET DI form.

Install

dotnet add package WACS.WASI.Preview2.DependencyInjection

Quick start — WasiPreview2RuntimeScope (one-shot embedder)

The simplest path: one disposable that owns the DI scope, fires every binding's BindToRuntime, and resolves the composite bundle.

using Wacs.Core.Runtime;
using Wacs.WASI.Preview2.DependencyInjection;

var runtime = new WasmRuntime();
using var wasi = new WasiPreview2RuntimeScope(
    runtime,
    preopens: new[] { ("./models", "/models") });

// wasi.Bundle      → composite hostBundle
//                    (Preview2 + WASI.NN forwarding when the
//                     WASI.NN.DependencyInjection sibling is on
//                     the load path)
// wasi.Resources   → single resource registry across subsystems
// wasi.Runtime     → runtime, with every wasi:* binding wired

// ... transpile the component, instantiate, invoke ...

WasiPreview2RuntimeScope is what wacs run --wasip2 uses internally. It auto-discovers Wacs.WASI.NN.DependencyInjection when present and registers the WasiPreview2NNBundle composite — no extra config when chaining wasi-nn alongside.

Quick start — IServiceCollection

For ASP.NET, generic-host worker services, or anywhere with an existing DI container:

using Microsoft.Extensions.DependencyInjection;
using Wacs.WASI.Preview2.DependencyInjection;

var services = new ServiceCollection();
services.AddWasiPreview2();   // every WASI 0.2.3 subsystem default registered

// Override individual subsystems via DI's normal TryAdd semantics:
services.AddSingleton<IOutgoingHandler>(_ =>
    new HttpClientOutgoingHandler(new HttpClient { Timeout = ... }));
services.AddSingleton<IEnvironment>(_ =>
    new SandboxedEnvironment(envVars: ..., args: ..., cwd: ...));

using var sp = services.BuildServiceProvider();
using var scope = sp.CreateScope();

var linker = scope.ServiceProvider.GetRequiredService<Linker>();
// linker.Runtime is the WasmRuntime with every wasi:* import bound

AddWasiPreview2(opts => opts.InstanceLifetime = ServiceLifetime.Scoped) is the default — fits ASP.NET request-scoped wasm execution. Pass Transient for per-call construction or Singleton for single-component apps.

Composing with WASI.NN

When WACS.WASI.NN.DependencyInjection is on the load path, the runtime scope auto-discovers it and registers the WasiPreview2NNBundle composite that forwards both Preview 2 and WASI.NN [WitSource] interface properties through one CLR object. The transpiler's direct-link IL casts to the composite type at the import call site; this package's auto-detection guarantees the expected type is present without any extra config.

What's included

  • Default impls for every WASI 0.2.3 subsystem: cli / clocks / filesystem / http / io / random / sockets
  • WasiPreview2Bundle (single-package) and WasiPreview2NNBundle (composite) bundle types
  • WasiPreview2Resources — the canonical resource registry direct-link emit looks up
  • WasiPreview2RuntimeScope — one-shot scope owning DI lifecycle, Linker resolution, and composite-bundle discovery

Documentation

  • docs/COMPONENT_CHAINING.md — runtime requirements, host-package composition, end-to-end CLI / embedder examples
  • Sibling package WACS.WASI.Preview2's README for manual subsystem wiring (no DI), per-impl override patterns

License

Apache-2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WACS.WASI.Preview2.DependencyInjection:

Package Downloads
WACS.WASI.NN.DependencyInjection

Microsoft.Extensions.DependencyInjection extension methods for WACS.WASI.NN. Registers the WasiNNBundle that the transpiler's HostPackageResolver direct-links wasi:nn imports against — symmetric with WACS.WASI.Preview2.DependencyInjection.

WACS.WASI.GFX.DependencyInjection

Microsoft.Extensions.DependencyInjection extension methods for WACS.WASI.GFX. Registers the WasiGfxBundle that the transpiler's HostPackageResolver will direct-link wasi-gfx imports against — symmetric with WACS.WASI.NN.DependencyInjection and WACS.WASI.Preview2.DependencyInjection. Preview: tracks the wasi-gfx proposal at WASI Phase 2 — the WIT surface may change as the proposal evolves.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2 95 5/16/2026
0.2.0 87 5/12/2026
0.1.8 137 5/11/2026
0.1.6 96 5/10/2026
0.1.5 131 5/10/2026
0.1.2 131 5/10/2026
0.1.1 97 5/9/2026
0.1.0 98 5/1/2026