Configuring a services HttpClient per tenant #561
-
Hello, i was wondering what is the best way to go about setting up a services HttpClient based on the current tenant info, i cant seem to use PerTenantOptions or named options because there are no httpclientoptions |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, the best method I've found it to use your own Options class with whatever settings you need in combination with a custom HttpClientHandler implementation which makes use of your Options class. Info on HttpClientHandler: I would register it as a transient and then register HttpClient with a factory method that instantiates the HttpClient with the HttpClientHandler. I hope this is helpful. |
Beta Was this translation helpful? Give feedback.
-
using options sounds like a better way than what i'm currently doing |
Beta Was this translation helpful? Give feedback.
Hi, the best method I've found it to use your own Options class with whatever settings you need in combination with a custom HttpClientHandler implementation which makes use of your Options class.
Info on HttpClientHandler:
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler?view=net-6.0
I would register it as a transient and then register HttpClient with a factory method that instantiates the HttpClient with the HttpClientHandler. I hope this is helpful.