0
votes

I am building an app in 2SXC for DNN using Razor templates. I need to pull some data from a couple external APIs, but have concerns over socket exhaustion using many HttpClient requests across different pages.

I have looked into using dependency injection and creating Typed Clients using IHttpClientFactory, but the current implementation in DNN doesn't appear to support this.

Does anyone have any suggestions on how to create and reuse HttpClient objects using razor modules that is thread safe?

Thanks for any guidance you can provide!

1
I can't figure out what you're doing. Are you worried that your api is going to be queried too often? or do you have some code which will query another API and you're worried that your server - acting as an http-client - will be causing too many connections? And what's the load you're worried about? I can't really think of a scenario that would cause so much trouble. - iJungleBoy
Thanks for the reply! I am concerned that the quantity of open sockets to the external API (not mine) as a client could potentially cause socket exhaustion or performance/memory issues.I have been referring to a couple of articles on best practices and came across this link - Yankee516

1 Answers

0
votes

Just my 2c but the article you're referring to is for .net core, intended for very high-load environments. So I'm almost certain your DNN endpoint probably won't have this.

Either way: from further research it looks like

  1. The Socket-Exhaustion mentioned is your program using sockets on it's own system (so not the remote api, your sockets are being blocked for a short time)
  2. You could easily just use a singleton - which is ok for 99% of all scenarios (create a static variable. The only downside I read of is that it caches DNS, but that's rarely important if your remote endpoint is always the same server, and there are workarounds like http://byterot.blogspot.com/2016/07/singleton-httpclient-dns.html