Skip to content

Investigate Support for Source Generator Based Dependency Injection in ASP.NET Core #62104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lakani opened this issue May 25, 2025 · 1 comment
Labels
NativeAOT needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Comments

@lakani
Copy link

lakani commented May 25, 2025

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.
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label May 25, 2025
@davidfowl
Copy link
Member

This has been filed at least 5 times. Closing this as a dupe

dotnet/runtime#82679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NativeAOT needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Projects
None yet
Development

No branches or pull requests

2 participants