question

MuhammadArsalanIftikhar-7431 avatar image
1 Vote"
MuhammadArsalanIftikhar-7431 asked Bruce-SqlWork answered

Overlap or restrictions http client NET 5.0, .NET Framework 4.8 & Mono

My current hobby project is a sdk that implements an open http protocol. I would like to cover a few runtimes, mainly NET5, Framework 4.8 and mono. Where possible cross-platform Another specific purifier is it makes a continous long polling call. The runtime diversity is mainly for learning purposes and to enable building a few different clients.

I have 2 questions.

Runtimes Are the specified runtimes too incompatible? I am mainly using http client and purosfully avoiding the new C# features. Models are in a net standard 2 library.

Http interface I created a wrapper for the http client, this is to initialize it properly and helps in a DI register function. The wrapper implements a custom http interface that is just a copy of put, post etc. For auth (JWT) I am using http messagehandler in DI.

Can I even use this typ of massage handler with a general interface across these runtimes? Some http clients differ ever so slightly in some places across runtimes. Next to that If I wanted to use blazor it could get weird with that http client.

I wanted to just put http clients in seperate projecs, add models proj to those and have a core sdk project dat references http clients depending on build. But my models cause a cyclic reference like that. The crossed out models folder in the sdk project is an internal models namespace.
104185-0rxo1.png


c++dotnet-runtimedotnet-aspnet-general
0rxo1.png (17.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MuhammadArsalanIftikhar-7431 ,
About using HTTPClient in ASP.Net Core as a DI Singleton,I suggest you could use HttpClientFactory.It will instantiate multiple httpclients and hold them in a static Dictionary.
More details,you could refer to below articles:
https://stackoverflow.com/questions/42065678/best-way-to-use-httpclient-in-asp-net-core-as-a-di-singleton
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
Best regards,
Yijing Sun

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

Create your libraries as .net standard 2.0 projects. There is HttpClient and HttpMessageHandler support.

The models project should not reference the http client library. Maybe you need 3 projects, models, communication, and interface.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.