[{"data":1,"prerenderedAt":550},["ShallowReactive",2],{"article-httpclient-saga-related-noteslinks":3},{"article":4,"tags":116,"previous":131,"next":302},{"id":5,"title":6,"author":7,"body":8,"createdAt":104,"description":105,"extension":106,"img":107,"meta":108,"navigation":109,"path":110,"seo":111,"stem":112,"tags":113,"updatedAt":104,"__hash__":115},"articles\u002Farticles\u002Fhttpclient-saga--related-noteslinks.md","HttpClient Saga and Related Notes Links","[object Object]",{"type":9,"value":10,"toc":100},"minimark",[11,29,45,48,62,65,80,83,86,93],[12,13,14,15,19,20,25,26],"p",{},"On ",[16,17,18],"strong",{},".Net Full framework",", you can control the number of outgoing client connections by setting ",[21,22,24],"a",{"href":23},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fapi\u002Fsystem.net.servicepointmanager.defaultconnectionlimit?view=netframework-4.7#System_Net_ServicePointManager_DefaultConnectionLimit","ServicePointManager.DefaultConnectionLimit"," to the desired number. ",[16,27,28],{},"It is 2 by default.",[12,30,14,31,34,35,39,40,44],{},[16,32,33],{},".Net Core",", you can set it by changing ",[21,36,38],{"href":37},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fapi\u002Fsystem.net.http.httpclienthandler.maxconnectionsperserver?view=netcore-2.0#System_Net_Http_HttpClientHandler_MaxConnectionsPerServer","HttpClientHandler.MaxConnectionsPerServer"," to your desired limit. The default is int.MaxValue -- much higher than the default for the full framework.  Gets or sets the maximum number of concurrent connections (per server endpoint) allowed when making requests using an ",[21,41,43],{"href":42},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fapi\u002Fsystem.net.http.httpclient?view=netcore-2.0","HttpClient"," object. Note that the limit is per server endpoint, so for example a value of 256 would permit 256 concurrent connections to http:\u002F\u002Fwww.adatum.com\u002F and another 256 to http:\u002F\u002Fwww.adventure-works.com\u002F",[12,46,47],{},"References:",[12,49,50,56,57,60],{},[21,51,55],{"href":23,"target":52,"rel":53},"_blank",[54],"noopener","ServicePointManager"," ",[58,59],"br",{},[21,61,38],{"href":37},[12,63,64],{},"Before the introduction of the HttpClientFactory in .NET Core 2.1, it was common to use the HttpClient to make HTTP requests to services.  One of the big problems with using the HttpClient was the misuse of it. HttpClient implements IDisposable, when anything implements IDisposable, best practice tells us that we should wrap the calls we are making inside a using statement to allow proper disposal of the object. However the HTTPClient is different, even though it implements IDisposable, we shouldn’t be wrapping this in a using statement. The HttpClient is reusable and thread safe, so it makes it very inefficient and unnecessary to dispose of the HttpClient after each request is made. When you dispose of the HttpClient object the underlying socket is not immediately released. This can cause some serious issues like ‘sockets exhaustion’. The recommended way is to instantiated it once and reused it throughout the life of an application.",[12,66,67,56,72,56,74,76,77,79],{},[21,68,71],{"href":69,"target":52,"rel":70},"https:\u002F\u002Faspnetmonsters.com\u002F2016\u002F08\u002F2016-08-27-httpclientwrong\u002F",[54],"YOU'RE USING HTTPCLIENT WRONG AND IT IS DESTABILIZING YOUR SOFTWARE",[58,73],{},[58,75],{},"Unfortunately, not disposing of our HttpClient instance does not fix all of the issues with the HttpClient. The issue with creating a single instance of the HttpClient is that it won’t respect DNS changes, because we are creating a single instance of the HttpClient, we are keeping the connection open, ready to be reused. ",[58,78],{},"Due to these issues, the HttpClientFactory was created.",[12,81,82],{},"Using the HttpClientFactory removes the issues that we can run into when using the HttpClient, such as ‘sockets exhaustion’, due to not re-using the HttpClient throughout the life of an application.",[12,84,85],{},"When reusing your HttpClient you could then run into the issue of the client not respecting DNS changes. While the HttpClientFactory by default has a handler lifetime set to 2 mins, to get around DNS change issue, we are also able to set this handler lifetime to whatever we want.",[12,87,88],{},[21,89,92],{"href":90,"target":52,"rel":91},"http:\u002F\u002Fanthonygiretti.com\u002F2018\u002F09\u002F06\u002Fhow-to-unit-test-a-class-that-consumes-an-httpclient-with-ihttpclientfactory-in-asp-net-core\u002F",[54],"How to unit test a class that consumes an HttpClient with IHttpClientFactory in ASP.NET Core?",[12,94,95],{},[21,96,99],{"href":97,"target":52,"rel":98},"https:\u002F\u002Fcodereview.stackexchange.com\u002Fquestions\u002F227596\u002Fsimple-httpclient-usage-for-integration-tests-in-net-core",[54],"Integration Testing",{"title":101,"searchDepth":102,"depth":102,"links":103},"",2,[],"2019-10-09T20:15:06.625Z","Recently, we migrated our applications to latest windows server from 2008 and ran into a number of issues with sockets, connection limits and timeouts.  The root of our issues is the default connection limits that we had not encountered before.  Below is part of our investigation and subsequent resolution to these issues.","md",null,{},true,"\u002Farticles\u002Fhttpclient-saga-related-noteslinks",{"title":6,"description":105},"articles\u002Fhttpclient-saga--related-noteslinks",[114],"netcore","l1pMNA9gO17s0hmcoHaNRdtKD9yGrQyXApQIDK9aZKI",[117],{"id":118,"title":119,"body":120,"description":124,"extension":106,"img":125,"meta":126,"name":114,"navigation":109,"path":127,"seo":128,"stem":129,"__hash__":130},"tags\u002Ftags\u002Fnetcore.md","Netcore",{"type":9,"value":121,"toc":122},[],{"title":101,"searchDepth":102,"depth":102,"links":123},[],".NET Core is a new version of .NET Framework, which is a free, open-source, general-purpose development platform maintained by Microsoft. It is a cross-platform framework that runs on Windows, macOS, and Linux operating systems.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fnetcore",{"description":124},"tags\u002Fnetcore","D5BWCPpKVXJTUKU0TRuD3sWQ9rXtqETGkxzHAK__g5w",{"id":132,"title":133,"author":107,"body":134,"createdAt":294,"description":295,"extension":106,"img":107,"meta":296,"navigation":109,"path":297,"seo":298,"stem":299,"tags":300,"updatedAt":294,"__hash__":301},"articles\u002Farticles\u002Faspnet-core-slow-start-up.md","ASP.NET CORE–Slow Start Up",{"type":9,"value":135,"toc":292},[136,139,244,247,279,288],[12,137,138],{},"I was trying to determine why my asp.net core application as so slow during startup (F5 w\u002Fdebugging).\nI believe I found one of the reasons.\nBy default, a new asp.net core application has an appsettings.Development.json file. \nWithin this file there are several settings to set the default log level.  Typically, you will see something like the following",[140,141,145],"pre",{"className":142,"code":143,"language":144,"meta":101,"style":101},"language-json shiki shiki-themes github-light github-dark","{ \n\"Logging\": \n    { \n        \"LogLevel\": \n        {  \n            \"Default\": \"Debug\", \n            \"System\": \"Information\", \n            \"Microsoft\": \"Information\"\n        } \n    }  \n}  \n","json",[146,147,148,157,166,172,180,186,202,215,226,232,238],"code",{"__ignoreMap":101},[149,150,153],"span",{"class":151,"line":152},"line",1,[149,154,156],{"class":155},"sVt8B","{ \n",[149,158,159,163],{"class":151,"line":102},[149,160,162],{"class":161},"sj4cs","\"Logging\"",[149,164,165],{"class":155},": \n",[149,167,169],{"class":151,"line":168},3,[149,170,171],{"class":155},"    { \n",[149,173,175,178],{"class":151,"line":174},4,[149,176,177],{"class":161},"        \"LogLevel\"",[149,179,165],{"class":155},[149,181,183],{"class":151,"line":182},5,[149,184,185],{"class":155},"        {  \n",[149,187,189,192,195,199],{"class":151,"line":188},6,[149,190,191],{"class":161},"            \"Default\"",[149,193,194],{"class":155},": ",[149,196,198],{"class":197},"sZZnC","\"Debug\"",[149,200,201],{"class":155},", \n",[149,203,205,208,210,213],{"class":151,"line":204},7,[149,206,207],{"class":161},"            \"System\"",[149,209,194],{"class":155},[149,211,212],{"class":197},"\"Information\"",[149,214,201],{"class":155},[149,216,218,221,223],{"class":151,"line":217},8,[149,219,220],{"class":161},"            \"Microsoft\"",[149,222,194],{"class":155},[149,224,225],{"class":197},"\"Information\"\n",[149,227,229],{"class":151,"line":228},9,[149,230,231],{"class":155},"        } \n",[149,233,235],{"class":151,"line":234},10,[149,236,237],{"class":155},"    }  \n",[149,239,241],{"class":151,"line":240},11,[149,242,243],{"class":155},"}\n",[12,245,246],{},"Keep in mind the order of settings are as follows going from very verbose to turned off.",[248,249,250,254,257,260,263,266,269],"ul",{},[251,252,253],"li",{},"Trace (Very Verbose)",[251,255,256],{},"Debug",[251,258,259],{},"Information",[251,261,262],{},"Warning",[251,264,265],{},"Error",[251,267,268],{},"Critical",[251,270,271,272,274,275,278],{},"None",[58,273],{},"\nI found that setting my development log settings to anything above Warning improved startup up time ",[16,276,277],{},"significantly","!",[12,280,281,282,287],{},"After I figured out above I did come across a Rick Strahl ",[21,283,286],{"href":284,"target":52,"rel":285},"https:\u002F\u002Fweblog.west-wind.com\u002Fposts\u002F2018\u002FDec\u002F31\u002FDont-let-ASPNET-Core-Default-Console-Logging-Slow-your-App-down#summary",[54],"post",".  If you don’t follow Rick do.",[289,290,291],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":101,"searchDepth":102,"depth":102,"links":293},[],"2019-12-08T03:45:40.058Z","In an effort to speed up my development process, I determined that changing the logging level, even in development made a huge difference.  Keep this in mind, and let me know if you find this useful.",{},"\u002Farticles\u002Faspnet-core-slow-start-up",{"title":133,"description":295},"articles\u002Faspnet-core-slow-start-up",[114],"Q1_YJbQEIsPuw5Us9AG0sFQVIpdMJzmtaPXHFL-GQ80",{"id":303,"title":304,"author":107,"body":305,"createdAt":542,"description":107,"extension":106,"img":335,"meta":543,"navigation":109,"path":544,"seo":545,"stem":546,"tags":547,"updatedAt":542,"__hash__":549},"articles\u002Farticles\u002Fvisual-studio-how-to-target-differentlatest-c-version-net-core-3-and-c-8.md","Visual Studio How to target different\u002Flatest c# version (.NET Core 3 and C# 8)",{"type":9,"value":306,"toc":540},[307,310,324,343,354,361,443,445,456,475,481,488,494,497,518,521,526,529,536],[12,308,309],{},"Know which version of c# you were actually using or wanting to try latest c# 8 features?  How to check?",[248,311,312,315,318,321],{},[251,313,314],{},"Open the project properties window (right click on project, select properties)",[251,316,317],{},"Select ‘Build’ from the left hand side options",[251,319,320],{},"Scroll down to the Advanced options",[251,322,323],{},"Select the desired version of c#, click ok   Wanting c# 8 selection? (released with .NET Core 3, and available as part of Visual Studio 2019 (latest release)     * For me, open Visual Studio select Help – Check for Updates (and download the latest release of VS.NET)",[12,325,326,338,339],{},[21,327,329],{"href":328},"\u002Farticles\u002Fimages\u002Fimage_637062268790299787.png",[330,331],"img",{"title":332,"style":333,"border":334,"alt":332,"src":335,"width":336,"height":337},"image","border: 0px currentcolor; border-image: none; display: inline; background-image: none;",0,"\u002Farticles\u002Fimages\u002Fimage_thumb_637062268791269872.png",393,100,"   After the update, open VS.NET revisit project properties and c# 8 should be available in the ‘Language Version’ selection list….but wait it is not there (the selection list is disabled and they gave me a clue…",[21,340,342],{"href":341,"target":52},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fcsharp\u002Flanguage-reference\u002Fconfigure-language-version","Why can’t I select a different c# version?",[12,344,345],{},[21,346,348],{"href":347},"\u002Farticles\u002Fimages\u002Fimage_637062268792583127.png",[330,349],{"title":332,"style":350,"border":334,"alt":332,"src":351,"width":352,"height":353},"margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;","\u002Farticles\u002Fimages\u002Fimage_thumb_637062268793729110.png",489,269,[12,355,356,360],{},[357,358,359],"em",{},"”The latest C# compiler determines a default language version based on your project's target framework or frameworks. This is because the C# language may have features that rely on types or runtime components that are not available in every .NET implementation. This also ensures that for whatever target your project is built against, you get the highest compatible language version by default.”","  Ok, so now the c# version is not selectable, it is based on the projects target framework. Here is the conversion chart…    ",[362,363,364,380],"table",{},[365,366,367],"thead",{},[368,369,370,374,377],"tr",{},[371,372,373],"th",{},"Target framework",[371,375,376],{},"version",[371,378,379],{},"C# language version default",[381,382,383,395,405,415,424,433],"tbody",{},[368,384,385,389,392],{},[386,387,388],"td",{},".NET Core",[386,390,391],{},"3.x",[386,393,394],{},"C# 8.0",[368,396,397,399,402],{},[386,398,388],{},[386,400,401],{},"2.x",[386,403,404],{},"C# 7.3",[368,406,407,410,413],{},[386,408,409],{},".NET Standard",[386,411,412],{},"2.1",[386,414,394],{},[368,416,417,419,422],{},[386,418,409],{},[386,420,421],{},"2.0",[386,423,404],{},[368,425,426,428,431],{},[386,427,409],{},[386,429,430],{},"1.x",[386,432,404],{},[368,434,435,438,441],{},[386,436,437],{},".NET Framework",[386,439,440],{},"all",[386,442,404],{},[58,444],{},[12,446,447,448],{},"Finally, that was my answer.  ",[21,449,451],{"href":450},"\u002Farticles\u002Fimages\u002Fimage_637062268794831916.png",[330,452],{"title":332,"style":333,"border":334,"alt":332,"src":453,"width":454,"height":455},"\u002Farticles\u002Fimages\u002Fimage_thumb_637062268796116567.png",499,293,[12,457,458,459,463,464,468,469,472,474],{},"References    ",[21,460,462],{"href":461,"target":52},"https:\u002F\u002Fdotnet.microsoft.com\u002Fdownload\u002Fdotnet-core\u002F3.0","Download .NET Core 3 Direct"," option Released 2019-09-23    ",[21,465,467],{"href":466,"target":52},"https:\u002F\u002Fwww.dotnetcurry.com\u002Fcsharp\u002F1489\u002Fcsharp-8-visual-studio-2019","New C# 8 Features","    ",[16,470,471],{},"One of the more important features…",[58,473],{},"\nNullable reference types (this is good addition)",[12,476,477,478,480],{},"The core idea is to allow variable type definitions to specify whether they can have null value assigned to them or not:     Weapon? canBeNull;",[58,479],{},"\nIWeapon cantBeNull;",[12,482,483,484,487],{},"Assigning a null value or a potential null value to a non-nullable variable results in a compiler warning\n(",[16,485,486],{},"the developer can configure the build to fail in case of such warnings, to be extra safe","):",[12,489,490,491,493],{},"canBeNull = null\n\u002F\u002F no warning",[58,492],{},"\ncantBeNull = null\n\u002F\u002F warning",[12,495,496],{},"cantBeNull = canBeNull;\n\u002F\u002F warning",[12,498,499,500,502,503,505,506,508,509,511,512,514,515,517],{},"Similarly, warnings are generated when dereferencing a nullable variable without checking it for null value first:",[58,501],{},"\ncanBeNull.Repair();\n\u002F\u002F warning",[58,504],{},"\ncantBeNull.Repair();\n\u002F\u002F no warning",[58,507],{},"\nif (canBeNull != null)",[58,510],{},"\n{",[58,513],{},"\ncanBeNull.Repair();\n\u002F\u002F no warning",[58,516],{},"\n}",[12,519,520],{},"The problem with such a change is that it breaks existing code:\nthe feature assumes that all variables from before the change are non-nullable.\nTo cope with that, static analysis for null-safety can be enabled selectively with a compiler switch at the project level.",[12,522,523],{},[16,524,525],{},"Developers can opt-in for nullability checking when they are ready to deal with the resulting warnings.",[12,527,528],{},"Still, this should be in their own best interest, as the warnings might reveal potential bugs in their code.",[12,530,531,532,535],{},"The switch is persisted as a property in the project file. There’s no user interface in Visual Studio 2019 yet for changing its value.\nTherefore, the following line must be ",[16,533,534],{},"added manually to the first PropertyGroup element of the project file to enable\nthe feature for the project",":",[537,538,539],"nullable-context-options",{},"\nenable\n",{"title":101,"searchDepth":102,"depth":102,"links":541},[],"2019-10-09T14:07:59.731Z",{},"\u002Farticles\u002Fvisual-studio-how-to-target-differentlatest-c-version-net-core-3-and-c-8",{"title":304,"description":107},"articles\u002Fvisual-studio-how-to-target-differentlatest-c-version-net-core-3-and-c-8",[548],"visualstudio","ypmVFhZTDDNRkorn4dMwIhgjCKVDrMBz-yfEqjhwNtM",1781574765308]