In a web-request I want to do a call to another server using Microsoft HttpClient. I am using MVC4 (hosted in IIS), and castle-windsor as IOC-container. I read that the HttpClient is designed to live during serveral calls, and my question is how I should implement this.
I come up with a few options:
- Ignore the fact that HttpClient is designed for multiple calls, and create a new one each time i need one.
- Create a Singleton(lifestyle in castle) object which stores the HttpClient between calls. Are there any risks with this? Will the performace be bad, if multiple web-request is using the same HTTP-client?
Are there any better pattern to do this?