Files
Luke c7af2d4cd3 Deprecate ReducerContext::identity in favor of database_identity (#4843)
## Summary
- add `ReducerContext::database_identity()` in Rust bindings
- deprecate `ReducerContext::identity()` and keep it as a compatibility
alias
- update reducer docs example to use `ctx.database_identity()`
- add C# reducer-context equivalent: `DatabaseIdentity` and obsolete
`Identity` alias
- update Rust/C# module test callsites to the new API name
- update C# codegen snapshots for generated `ReducerContext` API output

## Why
Issue #3201 reports user confusion between reducer `ctx.identity()`
(database/module identity) and `ctx.sender`. This change clarifies
naming while preserving compatibility.

## Validation
- `cargo check -p spacetimedb -p module-test` (Passed)
- `dotnet test crates/bindings-csharp/Codegen.Tests/Codegen.Tests.csproj
--nologo` (Passed)
- `dotnet test crates/bindings-csharp/Runtime.Tests/Runtime.Tests.csproj
--nologo` (Failed) pre-existing unrelated failure:
- `Runtime.Tests/JwtClaimsTest.cs(10,23): CS1729: 'JwtClaims' does not
contain a constructor that takes 2 arguments`

## Compatibility
- Rust: `identity()` still works but is deprecated in favor of
`database_identity()`.
- C#: `Identity` still works but is marked `[Obsolete]` in favor of
`DatabaseIdentity`.

Closes #3201
2026-05-04 19:50:39 +00:00
..
2023-11-30 14:54:26 +00:00
2026-04-30 19:24:41 +00:00

⚠️ Internal Project ⚠️

This project is intended for internal use only. It is not stable and may change without notice.

SpacetimeDB.Runtime

This project contains the runtime bindings for SpacetimeDB WebAssembly modules. See the C# module library reference for stable, user-facing documentation.

SpacetimeDB modules are compiled to WebAssembly modules that expose a specific interface; see the module ABI reference.

The runtime bindings are currently implementing via Wasi.Sdk package, which is a .NET implementation of the WASI standard. This is likely to change in the future.

While not really documented, it allows to build raw WebAssembly modules with custom bindings as well, which is what we're using here. The process is somewhat complicated, but here are the steps:

  • bindings.c declares raw C bindings to the SpacetimeDB FFI imports and marks them with attributes like __attribute__((import_module("spacetime"), import_name("_insert"))) that make them WebAssembly imports. (unfortunately, function name duplication is currently unavoidable)
  • bindings.c implements a bunch of Mono-compatible wrappers that convert between Mono types and raw types expected by the SpacetimeDB FFI and invoke corresponding raw bindings.
  • Runtime.cs declares corresponding functions with compatible signatures for Mono-compatible wrappers to attach to. It marks them all with [MethodImpl(MethodImplOptions.InternalCall)].
  • bindings.c attaches all those Mono-compatible wrappers to their C# declarations in a mono_stdb_attach_bindings function.
  • bindings.c adds FFI-compatible exports that search for a method by assembly name, namespace, class name and a method name in the Mono runtime and invoke it. Those exports are marked with attributes like __attribute__((export_name("__call_reducer__"))) so that they're exported from Wasm by the linker.
  • Finally, bindings.c implements no-op shims for all the WASI APIs so that they're linked internally and not attempted to be imported from the runtime itself.

The result is a WebAssembly module FFI-compatible with SpacetimeDB and with no WASI imports, which is what we need.

Regenerating RawModuleDef

To regenenerate the Autogen folder, run:

cargo run -p spacetimedb-codegen --example regen-csharp-moduledef

This folder contains the type definitions used to serialize the RawModuleDef that is returned by __describe_module__.