Skip to content

C# submodules - #5974

Open
lisandroct wants to merge 50 commits into
masterfrom
lisandro/csharp-submodules
Open

lisandroct wants to merge 50 commits into
masterfrom
lisandro/csharp-submodules

Conversation

@lisandroct

@lisandroct lisandroct commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description of Changes

Implements C# submodules (namespacing), following the proposal and reusing the existing V10 submodule representation.

  • Automatically discovers and registers referenced C# module assemblies.
  • Adds assembly-level [Namespace(typeof(AuthLib.Marker), Accessor = "MyAuth", Name = "auth_data" )] declarations. Accessor controls C# access; optional Name specifies the canonical database namespace. When omitted, the host derives it using the root module’s case-conversion policy. Dependencies without a namespace declaration register in public.
  • Allows the same module assembly to be published independently or used as a dependency, without a separate library build role.
  • Shares .NET 10 contexts across assemblies. Root code accesses ctx.Db.MyAuth.User; library helpers retain ctx.Db.User and use the caller’s context and transaction.
  • Supports namespace-aware tables, indexes, views, query builders, and scheduled reducers/procedures.
  • Generates nested C# client table, reducer, procedure, and subscription accessors using one connection and cache.
  • Caches resolved lookup names, SQL names, and index handles to avoid repeated resolution and unnecessary allocations.
  • Adds diagnostics, documentation, CI coverage, and focused integration tests.

API and ABI breaking changes

No changes to host, it uses the existing RawSubmoduleV10 for accessor namespaces and the existing ExplicitNames namespace mappings for canonical names.

On .NET 10, contexts move from generated module types into Runtime, changing their assembly identity. Existing standalone .NET 8 modules retain generated contexts.

Rollback safety impact

n/a

Expected complexity level and risk

4/5. This PR touches a lot of systems: source generation, runtime registration, NativeAOT publication, schema composition, function dispatch, client generation, subscriptions, ... possibly more.

The main risks are incorrect assembly ownership or dispatch ordering, cross-namespace lookup mistakes, NativeAOT export/trimming behavior, and regressions in existing flat modules.

Testing

  • .NET 8 and .NET 10 generator/Verify suites; regenerated snapshots.
  • Rust codegen tests, including C# bindings generated from a TypeScript submodule.
  • NativeAOT publication, root export selection, and cross-library helper/HTTP integration.
  • Namespace client integration: subscriptions, callbacks, indexes, views, events, private tables, one-off queries, and unsubscribe cleanup.
  • Namespaced scheduled reducers/procedures and cross-namespace transaction commit/rollback.
  • Root-defined RLS targeting namespaced tables and environment-security integration.
  • Distinct accessor/canonical names (MyAuth → auth_data) and default namespace case conversion (MyAuth → my_auth).
  • Full C# SDK unit-test suite.

@lisandroct
lisandroct marked this pull request as draft September 23, 2026 17:07
@lisandroct
lisandroct force-pushed the lisandro/csharp-submodules branch 2 times, most recently from 7ee3c50 to ab24ef3 Compare September 28, 2026 14:05
@lisandroct
lisandroct marked this pull request as ready for review September 28, 2026 15:18
@lisandroct
lisandroct force-pushed the lisandro/csharp-submodules branch 2 times, most recently from 03252b0 to 3d1b967 Compare October 1, 2026 14:32

@JasonAtClockwork JasonAtClockwork left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works as intended but I did find some differences between how the TypeScript submodules work compared against the C#. I'm not certain if any of these are real problems so we may want a discussion around them:

  1. HTTP routes from submodules are ignored in TypeScript but are bound to the root in C# (which can cause collisions)
  2. TypeScript supports nested submodules, and generating a C# client against a TypeScript module with nested submodules causes spacetime generate to panic
  3. TypeScript submodules are declared, not discovered. C# discovers every referenced module and merges anything not mounted into the root (master currently just ignored them), which can cause collisions with the root's reducers, Init, or types and allows access to root env variables.

Super low priority: Codegen.Tests fails on Windows however is fine on Linux

@lisandroct

Copy link
Copy Markdown
Contributor Author
1. HTTP routes from submodules are ignored in TypeScript but are bound to the root in C# (which can cause collisions)

The proposal doesn't say anything about HTTP handlers. I decided to not ignore them, but it might be better to do so.

2. TypeScript supports nested submodules, and generating a C# client against a TypeScript module with nested submodules causes `spacetime generate` to panic

The proposal only describes submodules being defined in root and I was under the impression that the plan was to not support nested submodules, so I just didn't add support to them. But now I'm not sure. Maybe we do want them?

3. TypeScript submodules are declared, not discovered. C# discovers every referenced module and merges anything not mounted into the root (master currently just ignored them), which can cause collisions with the root's reducers, Init, or types and allows access to root env variables.

The proposal states: "A library added as a dependency and otherwise ignored still has its tables register in public, exactly as today; what changes is that the consumer can redirect them to a named namespace via a mount declaration". So I understand the behavior on this branch is the desired one. All dependencies are registered in public unless root defines a namespace for them.

@lisandroct
lisandroct force-pushed the lisandro/csharp-submodules branch from 3d1b967 to 6278735 Compare October 6, 2026 13:32

@JasonAtClockwork JasonAtClockwork left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jdetter jdetter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm only required for the CI change and that looks fine to me. I didn't review any of the other code.

@lisandroct
lisandroct added this pull request to the merge queue Oct 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 8, 2026
@lisandroct
lisandroct force-pushed the lisandro/csharp-submodules branch from ad38fb3 to 7f91b8f Compare October 8, 2026 18:39
@lisandroct
lisandroct enabled auto-merge October 8, 2026 18:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants