Question regarding multiple calls to AddHttpClient()
I have a class library that calls this:
Then the main project calls this:
Can it cause any issues?
7 Replies
Hi, how are you? plz type in chatGPT.
Kindly, fuck off with this sort of an answer
Unlikely to cause issues, but just strictly unnecessary
I am sorry.
Thanks for your response. Then I am wondering how the double call to
AddHttpClient()
can be avoided – as both projects need the IHttpClientFactory
injected, but none knows if the other has added it.One thing that comes to mind is using typed clients
That way, the library would have it's own client, and the app would have it's own (or multiple)
Could maybe make it
internal
too, so the app cannot just inject itYour business layer shouldn't be aware of the service collection at all really. That's an application layer concern.
Business layer really should just be defining all your services and not worrying about how the services get their dependencies.
Application layer actually handles sewing it all together with DI and running it
It's no problem, the AddHttpClient method will only add if it hasn't been added before.
You can see https://source.dot.net/#Microsoft.Extensions.Http/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs,72bc67c4aadb77fc