Replies: 2 comments 4 replies
-
I was looking at the code and thought of something similar. Essentially there could be an attribute The service type could then be tested for the attribute during service registration. On resolving, if the type has the N.B. The place this suggestion falls apart is that a lot of the code generated must reference internal classes such as Edit: On second review I'm not sure that this is feasible since a lot of the work is done at runtime such that the compiler doesn't know for example which constructor to call. The runtime code generation does indeed take advantage of runtime knowledge i.e. it's not a pure function of the type. |
Beta Was this translation helpful? Give feedback.
-
See #82679 |
Beta Was this translation helpful? Give feedback.
-
I've tried to take a few deep dives into the way Dependency Injection works through Service Provider and Descriptor and things. From what I can tell, when the time comes to prepare dependencies for a service, the
Activator
is used and relies heavily on dynamically accessed members. It would be amazing if we could utilize [a] source generator[s] to circumvent using reflection and the Activator to construct our service implementations. For my use case I would think that'd help with cold start situations in my azure services but what I'd really be after is better AOT support when using the baked in DI capabilities. My added hope would be that it could help with creating somewhat cleaner bootstrap code in a given Program.cs (especially for minimal apps) as the generator could also produce a tailor madeAddServices
method which includes all decorated implementations.Beta Was this translation helpful? Give feedback.
All reactions