Description
Is your feature request related to a problem? Please describe the problem.
Currently, Microsoft.Extensions.DependencyInjection uses runtime reflection for dependency resolution, which introduces startup overhead and can present challenges for AOT (Ahead-Of-Time) scenarios (e.g., NativeAOT, Blazor WebAssembly). Community libraries such as Jab, ThunderboltIoc, and SourceInject demonstrate that C# source generators can provide compile-time DI containers that are significantly faster and more AOT-friendly.
Describe the solution you'd like
Investigate and consider implementing support for source generator-based dependency injection in ASP.NET Core. This could involve providing an official Roslyn-based source generator or a pluggable system, allowing developers to benefit from:
- Compile-time validation of DI configuration
- No runtime reflection for resolution
- Reduced startup time and memory usage
- Improved compatibility with NativeAOT and similar workloads
Describe the alternatives you've considered
Alternatives include continuing with the current reflection-based system or using third-party libraries, but these lack official integration and may not support all ASP.NET Core patterns. Adopting a hybrid approach or providing extensibility points for DI source generators are also possible solutions.
Additional context
- Community libraries: Jab, ThunderboltIoc, SourceInject
- No open issue currently exists in aspnetcore specifically tracking source generator DI.
- This feature could provide significant benefits for performance-critical and AOT workloads.