Skip to main content

๐Ÿš€ NativeAOT and Trimming

GenDI is built to avoid runtime reflection-heavy registration paths.

๐Ÿ“ What is included in this repositoryโ€‹

  • ๐Ÿ“„ src/GenDI/ILLink.xml descriptor support
  • ๐Ÿ”ฌ Trim publish validation app under tests/GenDI.Phase3.TrimValidation.App
  • ๐Ÿ”ฌ NativeAOT publish validation app under tests/GenDI.Phase3.NativeAotValidation.App
  • ๐Ÿงช Automated validation tests under tests/GenDI.Phase3.Validation.Tests

๐Ÿ’ก Why this mattersโ€‹

NativeAOT and trim modes can remove metadata/code paths not statically referenced. GenDI reduces this risk by emitting direct activation code.

โš ๏ธ Reflection-based DI scanners (Assembly.GetTypes()) are incompatible with trimming and AOT โ€” they produce binaries that crash at runtime. GenDI's generated factories are fully static and AOT-safe.

dotnet publish tests/GenDI.Phase3.TrimValidation.App/GenDI.Phase3.TrimValidation.App.csproj -c Release
dotnet publish tests/GenDI.Phase3.NativeAotValidation.App/GenDI.Phase3.NativeAotValidation.App.csproj -c Release

๐Ÿ† Best practicesโ€‹

  • ๐ŸŽฏ Prefer explicit contracts via Injectable<TService>.
  • ๐Ÿ”’ Keep property injection limited to required init-only dependencies.
  • ๐Ÿ”„ Validate trim and NativeAOT outputs in CI.