Status
Accepted (Revised, 2026-07-28).
Context
Runtime assembly scanning, attribute reflection, dynamic generic creation, and runtime expression mapping widen trim risk and push architecture errors to startup or request time. Old templates left mechanical discovery to runtime, causing AOT-exemption bloat, missed registrations, and tests that protected handwritten file shapes instead of invariants.
Decision
Source Generator First. DI registration, endpoint routing, validation rules, JSON context, DTO projection, QueryShape, the standard list-query plan, ORM Fluent config, and module manifests default to source generation or explicit generation entries. Runtime reflection is allowed only as a registered migration exception.
Generators already in use: Mapperly, Mediator.SourceGenerator, System.Text.Json SG, the ORM Fluent Configuration Generator, the QueryShape Generator, and the DI/Endpoint/Validation generators. The ORM Fluent Configuration Generator reads provider-neutral [BitzTable]/[BitzColumn]/[BitzIndex] metadata at compile time and emits EF Core IEntityTypeConfiguration<T> plus SqlSugar static Fluent mapping. Runtime reflection to scan aggregate attributes and build ORM mapping is banned; the default aggregate↔entity mapper is no longer generated.
The API Host uses a build-only JSON Contract Compiler to aggregate JSON roots semantically before CoreCompile, then passes ordinary C# declarations to the official System.Text.Json SG. Discovery is not limited to [GenerateEndpoint]; it covers handwritten Minimal APIs, custom Map extensions, ASP.NET IResult factories, and Host HTTP JSON calls. It must not maintain framework method-name lists, product assembly prefixes, or a global [JsonSerializable] catalog. Module-private persistence, signing, token, and external-protocol boundaries keep small local Contexts and pass JsonTypeInfo explicitly.
The hard gate (REQ-GATE-001) blocks Assembly.GetTypes(), GetCustomAttributes(), Activator.CreateInstance(), MakeGenericType(), GetMethod()/Invoke(), runtime Query-attribute reflection, and runtime persistence-metadata ORM mapping — all P0 unless registered as AOT-EXEMPT. The one exception is Mediator PipelineBehaviors ordering, which stays explicit (ADR 0401) and is not auto-registered.
Consequences
AOT/Trim safety rises, boilerplate falls, and architecture errors shift to compile time. Host startup is lighter and more predictable. The cost is generator count and complexity: snapshot tests, semantic tests, and IDE-refresh maintenance; the QueryStore escape hatch covers queries a generator cannot express.