๐ NativeAOT and Trimming
GenDI is built to avoid runtime reflection-heavy registration paths.
๐ What is included in this repositoryโ
- ๐
src/GenDI/ILLink.xmldescriptor 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.
โ Recommended publish checksโ
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.