[Event Sourcing] Running an Existing C# Business Model on Wasm with SekibanWasmRuntime
In the previous article, we created a C# application using Sekiban DCB to handle students, classes, and class enrollment. This time, we will try running that application with SekibanWasmRuntime , which allows Sekiban to run with Wasm (WebAssembly). In this article, we will run a project written in C# as Wasm. SekibanWasmRuntime currently provides primary support for C# and Rust, while Go,…
The article discusses running a C# business model using SekibanWasmRuntime, which allows Sekiban to run with WebAssembly (Wasm). Sekiban is an event sourcing framework that stores application events and builds the current state from them. Wasm is an executable format produced by compiling code. SekibanWasmRuntime currently supports running C# and Rust applications as Wasm, with other languages available as experimental implementations. The sample code for this example is available online.
Sekiban handles roles similar to Wasm, with Wasm executing the business code, while Sekiban provides the environment and event storage mechanism. The architecture involves the API, ISekibanExecutor, RemoteSekibanExecutor, SekibanWasmRuntime, and PostgreSQL storage. When a student is created, an event is generated by the existing Command handler, stored by the Runtime, and applied by the Wasm Projector when state is retrieved or the student list is updated.
To run the existing C# business logic as Wasm, several changes were made. A Wasm project was created, referencing the existing EventSource and building it as Wasm. An entry point and type registration were added to connect the Runtime to the existing Projector and provide necessary type information. Build scripts were added to generate the Wasm file inside Docker.
The Runtime container and a dedicated PostgreSQL instance were also set up. The ISekibanExecutor implementation was replaced with RemoteSekibanExecutor on the API side, allowing the API to communicate with the Runtime over HTTP.
The Wasm project references the existing code and includes necessary configurations. The package and Wasm configuration involve adding the Sekiban.Dcb.WasmRuntime.Aspire and Sekiban.Dcb.WasmRuntime.Remote packages to the API and AppHost projects. Settings are added to the Wasm project to generate Wasm output using .NET 10, WASI-Wasm runtime identifier, library output type, and other relevant settings. Finally, package references for NativeAOT-LLVM and linker settings are included to expose functions called by the Runtime.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.