Open Chicagoan2016 opened 4 years ago
The current (dotnetcore) recommendation is to use HttpClientFactory
. I don't know if that's available in the version of .NET you are using?
Also in ASP.NET Core (which I think you can use from .NET Framework 4.7+) you can use dependency injection to create/get/manage an HttpClientFactory
and/or HttpClient
instance. And in CSLA 5 you can get that instance via DI as well.
If your version of .NET and/or ASP.NET and/or CSLA is older than that, then you'll probably need to put that HttpClient
instance into a static
and using it from there - but I can't believe that's Microsoft's recommendation.
@rockfordlhotka Do we have a sample (test or commit will do) for this:
And in CSLA 5 you can get that instance via DI as well.
I think the BlazorExample sample might do this.
I have a business object that needs to read data from a REST based API, based on https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client I need to use HttpClient but only instantiate it once throughout the life of an application. my application is ASP.NET so If I instantiate HttpClient in Global.asax, how am I going to use it in business/datalayer? or should I take a different approach? your help will be appreciated.
Kind Regards