Open TechnoBerry opened 1 year ago
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
Author: | AMalininHere |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-Extensions-HttpClientFactory` |
Milestone: | - |
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection See info in area-owners.md if you want to be subscribed.
Author: | AMalininHere |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `untriaged`, `area-Extensions-DependencyInjection` |
Milestone: | - |
Background and motivation
In most of the cases in which I had to use
ActivatorUtilities.CreateFactory
, all the passed types were known. It seems to me that the method generation using expression trees used under the hood of theActivatorUtilities.CreateFactory
method is redundant in my case and can be replaced with a method created using source generator. I also saw that theAddHttpClient
method fromMicrosoft.Extensions.Http
has an overload, in combination with which the source generator will look appropriate.API Proposal
I suggest adding an attribute (e.g.
CreateInstanceAttribute
) to mark methods for which source should be generated and a source generator that will generate an implementation of the factory method using the passed parameters and dependencies obtained from IServiceProviderAPI Usage
Below is an example of using with AddHttpClient.
Alternative Designs
No response
Risks
No response