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
<PackageReference Include="WACS.WASI.Preview2.DependencyInjection" Version="0.2.2" />
<PackageVersion Include="WACS.WASI.Preview2.DependencyInjection" Version="0.2.2" />
<PackageReference Include="WACS.WASI.Preview2.DependencyInjection" />
paket add WACS.WASI.Preview2.DependencyInjection --version 0.2.2
#r "nuget: WACS.WASI.Preview2.DependencyInjection, 0.2.2"
#:package WACS.WASI.Preview2.DependencyInjection@0.2.2
#addin nuget:?package=WACS.WASI.Preview2.DependencyInjection&version=0.2.2
#tool nuget:?package=WACS.WASI.Preview2.DependencyInjection&version=0.2.2
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) andWasiPreview2NNBundle(composite) bundle typesWasiPreview2Resources— the canonical resource registry direct-link emit looks upWasiPreview2RuntimeScope— 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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- WACS (>= 0.15.20)
- WACS.ComponentModel (>= 0.4.0)
- WACS.WASI.Preview2 (>= 0.5.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- WACS (>= 0.15.20)
- WACS.ComponentModel (>= 0.4.0)
- WACS.WASI.Preview2 (>= 0.5.0)
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.