[{"data":1,"prerenderedAt":648},["ShallowReactive",2],{"article-aspnet-core-slow-start-up":3},{"article":4,"tags":188,"previous":203,"next":549},{"id":5,"title":6,"author":7,"body":8,"createdAt":177,"description":178,"extension":179,"img":7,"meta":180,"navigation":181,"path":182,"seo":183,"stem":184,"tags":185,"updatedAt":177,"__hash__":187},"articles\u002Farticles\u002Faspnet-core-slow-start-up.md","ASP.NET CORE–Slow Start Up",null,{"type":9,"value":10,"toc":175},"minimark",[11,15,122,125,159,171],[12,13,14],"p",{},"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",[16,17,22],"pre",{"className":18,"code":19,"language":20,"meta":21,"style":21},"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","",[23,24,25,34,44,50,58,64,80,93,104,110,116],"code",{"__ignoreMap":21},[26,27,30],"span",{"class":28,"line":29},"line",1,[26,31,33],{"class":32},"sVt8B","{ \n",[26,35,37,41],{"class":28,"line":36},2,[26,38,40],{"class":39},"sj4cs","\"Logging\"",[26,42,43],{"class":32},": \n",[26,45,47],{"class":28,"line":46},3,[26,48,49],{"class":32},"    { \n",[26,51,53,56],{"class":28,"line":52},4,[26,54,55],{"class":39},"        \"LogLevel\"",[26,57,43],{"class":32},[26,59,61],{"class":28,"line":60},5,[26,62,63],{"class":32},"        {  \n",[26,65,67,70,73,77],{"class":28,"line":66},6,[26,68,69],{"class":39},"            \"Default\"",[26,71,72],{"class":32},": ",[26,74,76],{"class":75},"sZZnC","\"Debug\"",[26,78,79],{"class":32},", \n",[26,81,83,86,88,91],{"class":28,"line":82},7,[26,84,85],{"class":39},"            \"System\"",[26,87,72],{"class":32},[26,89,90],{"class":75},"\"Information\"",[26,92,79],{"class":32},[26,94,96,99,101],{"class":28,"line":95},8,[26,97,98],{"class":39},"            \"Microsoft\"",[26,100,72],{"class":32},[26,102,103],{"class":75},"\"Information\"\n",[26,105,107],{"class":28,"line":106},9,[26,108,109],{"class":32},"        } \n",[26,111,113],{"class":28,"line":112},10,[26,114,115],{"class":32},"    }  \n",[26,117,119],{"class":28,"line":118},11,[26,120,121],{"class":32},"}\n",[12,123,124],{},"Keep in mind the order of settings are as follows going from very verbose to turned off.",[126,127,128,132,135,138,141,144,147],"ul",{},[129,130,131],"li",{},"Trace (Very Verbose)",[129,133,134],{},"Debug",[129,136,137],{},"Information",[129,139,140],{},"Warning",[129,142,143],{},"Error",[129,145,146],{},"Critical",[129,148,149,150,153,154,158],{},"None",[151,152],"br",{},"\nI found that setting my development log settings to anything above Warning improved startup up time ",[155,156,157],"strong",{},"significantly","!",[12,160,161,162,170],{},"After I figured out above I did come across a Rick Strahl ",[163,164,169],"a",{"href":165,"target":166,"rel":167},"https:\u002F\u002Fweblog.west-wind.com\u002Fposts\u002F2018\u002FDec\u002F31\u002FDont-let-ASPNET-Core-Default-Console-Logging-Slow-your-App-down#summary","_blank",[168],"noopener","post",".  If you don’t follow Rick do.",[172,173,174],"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":21,"searchDepth":36,"depth":36,"links":176},[],"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.","md",{},true,"\u002Farticles\u002Faspnet-core-slow-start-up",{"title":6,"description":178},"articles\u002Faspnet-core-slow-start-up",[186],"netcore","Q1_YJbQEIsPuw5Us9AG0sFQVIpdMJzmtaPXHFL-GQ80",[189],{"id":190,"title":191,"body":192,"description":196,"extension":179,"img":197,"meta":198,"name":186,"navigation":181,"path":199,"seo":200,"stem":201,"__hash__":202},"tags\u002Ftags\u002Fnetcore.md","Netcore",{"type":9,"value":193,"toc":194},[],{"title":21,"searchDepth":36,"depth":36,"links":195},[],".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":196},"tags\u002Fnetcore","D5BWCPpKVXJTUKU0TRuD3sWQ9rXtqETGkxzHAK__g5w",{"id":204,"title":205,"author":7,"body":206,"createdAt":541,"description":542,"extension":179,"img":251,"meta":543,"navigation":181,"path":544,"seo":545,"stem":546,"tags":547,"updatedAt":541,"__hash__":548},"articles\u002Farticles\u002Faspnet-core-3-things-i-learned-pro-tips-migration-to-aspnet-core-3.md","ASP.NET Core 3 Things I Learned \u002F Pro Tips \u002F Migration to ASP.NET Core 3",{"type":9,"value":207,"toc":539},[208,240,255,263,266,377,392,398,424,447,452,457,471,536],[126,209,210,216,219,222,225,228,231,234,237],{},[129,211,212,213],{},"Starting up the web application with ",[155,214,215],{},"dotnet run",[129,217,218],{},"there are CLI parameters that you can use to set environment, port etc.",[129,220,221],{},"uses Kestrel to host the application",[129,223,224],{},"windows authentication cannot be turned on with dotnet run",[129,226,227],{},"can configure default behavior from within Visual Studio project properties",[129,229,230],{},"Debug, select Launch “Project” then you can set the App Url, default page, etc.",[129,232,233],{},"Hitting debug F5 within Visual Studio when the {Project Name} profile is selected hosts the application on Kestrel similar to dotnet run",[129,235,236],{},"dotnet run –e development will set the environment variable to ‘production’ (",[129,238,239],{},"in the following image you can see that I set the default environment for Kestrel runs to Development",[12,241,242,243],{},"ASPNETCORE_ENVIRONMENT Development\n",[163,244,246],{"href":245},"\u002Farticles\u002Fimages\u002Fimage_637115214952391737.png",[247,248],"img",{"style":249,"title":250,"src":251,"alt":250,"width":252,"height":253,"border":254},"border: 0px currentcolor; display: inline; background-image: none;","image","\u002Farticles\u002Fimages\u002Fimage_thumb_637115214953620084.png",545,336,0,[126,256,257,260],{},[129,258,259],{},"JSON properties are now lower case in asp.net core (i.e. when return json from a method Json({object here}) would have all properties changed to lower case)",[129,261,262],{},"use the following code to avoid camel case names by default \nservices.AddControllersWithViews()\n       .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());",[12,264,265],{},"{\"Id\":9000,\"FullName\":\"John Smith\"} would be serialized to {\"id\":9000,\"fullName\":\"John Smith\"}       ",[126,267,268,277,280,287,344,361,370],{},[129,269,270,271,276],{},"Debug ASP.NET Core apps in Visual Studio IIS\u002FIISExpress etc. reference ",[163,272,275],{"href":273,"target":166,"rel":274},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fvisualstudio\u002Fdebugger\u002Fhow-to-enable-debugging-for-aspnet-applications?view=vs-2019",[168],"here","        ",[129,278,279],{},"After setting a application within IIS, setting authentication to windows, selecting application pool with no managed code – you may get the following…\nThe in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application.",[129,281,282],{},[163,283,286],{"href":284,"target":166,"rel":285},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fhost-and-deploy\u002Fiis\u002F?view=aspnetcore-2.2",[168],"Host ASP.NET Core on Windows with IIS",[129,288,289,290,293,297],{},"In order to ready http request bodies in a synchronous manner I had to add following service configuration\n",[163,291],{"href":292},"https:\u002F\u002Fstackoverflow.com\u002Fquestions\u002F47735133\u002Fasp-net-core-synchronous-operations-are-disallowed-call-writeasync-or-set-all",[163,294,292],{"href":292,"rel":295},[296],"nofollow",[16,298,302],{"className":299,"code":300,"language":301,"meta":21,"style":21},"language-cs shiki shiki-themes github-light github-dark","\u002F\u002F If using Kestrel: \n\u002F\u002Fservices.Configure&lt;KestrelServerOptions>(options => \n\u002F\u002F{ \n\u002F\u002Foptions.AllowSynchronousIO = true; \n\u002F\u002F});\n\u002F\u002F If using IIS: \nservices.Configure > IISServerOptions>(options => { \noptions.AllowSynchronousIO = true; })  \n","cs",[23,303,304,309,314,319,324,329,334,339],{"__ignoreMap":21},[26,305,306],{"class":28,"line":29},[26,307,308],{},"\u002F\u002F If using Kestrel: \n",[26,310,311],{"class":28,"line":36},[26,312,313],{},"\u002F\u002Fservices.Configure&lt;KestrelServerOptions>(options => \n",[26,315,316],{"class":28,"line":46},[26,317,318],{},"\u002F\u002F{ \n",[26,320,321],{"class":28,"line":52},[26,322,323],{},"\u002F\u002Foptions.AllowSynchronousIO = true; \n",[26,325,326],{"class":28,"line":60},[26,327,328],{},"\u002F\u002F});\n",[26,330,331],{"class":28,"line":66},[26,332,333],{},"\u002F\u002F If using IIS: \n",[26,335,336],{"class":28,"line":82},[26,337,338],{},"services.Configure > IISServerOptions>(options => { \n",[26,340,341],{"class":28,"line":95},[26,342,343],{},"options.AllowSynchronousIO = true; })\n",[129,345,346,347,352,353],{},"dotnet – info Shows what versions are installed on your workstation (",[163,348,351],{"href":349,"target":166,"rel":350},"https:\u002F\u002Fweblog.west-wind.com\u002Fposts\u002F2018\u002FJun\u002F05\u002FWhich-NET-Core-Runtime-Download-do-you-need",[168],"Reference Rick Strahl",")\n",[163,354,356],{"href":355},"\u002Farticles\u002Fimages\u002Fimage_637115214954889487.png",[247,357],{"style":249,"title":250,"src":358,"alt":250,"width":359,"height":360,"border":254},"\u002Farticles\u002Fimages\u002Fimage_thumb_637115214956154680.png",353,206,[129,362,363,364,367],{},"This looks really interesting but I have yet to install\u002Ftry it out Live Reload using dotnet watch ",[163,365],{"href":366},"https:\u002F\u002Fweblog.west-wind.com\u002Fposts\u002F2019\u002FJun\u002F03\u002FBuilding-Live-Reload-Middleware-for-ASPNET-Core",[163,368,366],{"href":366,"rel":369},[296],[129,371,372,373,376],{},"IHostBuilder vs IWebHostBuilder – ASP.NET Core is used to build http endpoints using Kestrel web server. \nIWebHostbuilder ",[155,374,375],{},"remains for backward compatibility only",", and was used to encapsulate DI, Logging and configuration.  This was used in earlier versions of ASP.NET Core 3 for http workloads.",[12,378,379,380,385,386,391],{},"The default .NET Core 3 ASP.NET Core template sets up by default in the program.cs IHostBuilder, which is the ",[163,381,384],{"href":382,"target":166,"rel":383},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fhost\u002Fweb-host?view=aspnetcore-3.1",[168],"recommended"," for all app types.  Documentation can be found at ",[163,387,390],{"href":388,"target":166,"rel":389},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fhost\u002Fgeneric-host?view=aspnetcore-3.1",[168],"docs.microsoft.com",".  A host can encapsulates dependency injection, logging, configuration, IHostedService implementations.  Hosting is no longer bound to Kestrel and no longer bound to ASP.NET Core (oddly, this means you can start a host that doesn’t require Kestrel and doesn’t even need the ASP.NET Core Framework)",[12,393,394,397],{},[155,395,396],{},"CreateHostBuilder"," has the following defaults",[126,399,400,413,416],{},[129,401,402,403,407,408,412],{},"Sets the ",[163,404,406],{"href":405},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Findex?view=aspnetcore-3.1#content-root","content root"," to the path returned by ",[163,409,411],{"href":410},"https:\u002F\u002Fdocs.microsoft.com\u002Fdotnet\u002Fapi\u002Fsystem.io.directory.getcurrentdirectory","GetCurrentDirectory",".",[129,414,415],{},"Loads host configuration from:\n----- Environment variables prefixed with \"DOTNET_\".\n----- Command-line arguments.",[129,417,418,419,423],{},"Loads app configuration from:\n----- appsettings.json.\n----- appsettings.{Environment}.json.\n----- ",[163,420,422],{"href":421},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fsecurity\u002Fapp-secrets?view=aspnetcore-3.1","Secret Manager"," when the app runs in the Development environment.\n----- Environment variables.\n----- Command-line arguments.",[126,425,426,434],{},[129,427,428,429,433],{},"Adds the following ",[163,430,432],{"href":431},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Flogging\u002Findex?view=aspnetcore-3.1","logging"," providers:\n----- Console\n----- Debug\n----- EventSource\n----- EventLog (only when running on Windows)",[129,435,436,437,441,442,446],{},"Enables ",[163,438,440],{"href":439},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fdependency-injection?view=aspnetcore-3.1#scope-validation","scope validation"," and ",[163,443,445],{"href":444},"https:\u002F\u002Fdocs.microsoft.com\u002Fdotnet\u002Fapi\u002Fmicrosoft.extensions.dependencyinjection.serviceprovideroptions.validateonbuild#Microsoft_Extensions_DependencyInjection_ServiceProviderOptions_ValidateOnBuild","dependency validation"," when the environment is Development.",[12,448,449],{},[155,450,451],{},"ConfigureWebHostDefaults ",[126,453,454],{},[129,455,456],{},"Loads host configuration from environment variables prefixed with \"ASPNETCORE_\".",[126,458,459],{},[129,460,461,462,466,467,412],{},"Sets ",[163,463,465],{"href":464},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fservers\u002Fkestrel?view=aspnetcore-3.1","Kestrel"," server as the web server and configures it using the app's hosting configuration providers. For the Kestrel server's default options, see ",[163,468,470],{"href":469},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fservers\u002Fkestrel?view=aspnetcore-3.1#kestrel-options","Kestrel web server implementation in ASP.NET Core",[126,472,473,480,487,493,501,507,510,519,528],{},[129,474,475,476,412],{},"Adds ",[163,477,479],{"href":478},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fservers\u002Fkestrel?view=aspnetcore-3.1#host-filtering","Host Filtering middleware",[129,481,475,482,486],{},[163,483,485],{"href":484},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fhost-and-deploy\u002Fproxy-load-balancer?view=aspnetcore-3.1#forwarded-headers","Forwarded Headers middleware"," if ASPNETCORE_FORWARDEDHEADERS_ENABLED=true.",[129,488,489,490,412],{},"Enables IIS integration. For the IIS default options, see ",[163,491,286],{"href":492},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fhost-and-deploy\u002Fiis\u002Findex?view=aspnetcore-3.1#iis-options",[129,494,495,496,500],{},"Configuration for Framework-provided services can be found ",[163,497,275],{"href":498,"target":166,"rel":499},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fhost\u002Fgeneric-host?view=aspnetcore-3.1#framework-provided-services",[168]," (any host lifetime, environment etc.)",[129,502,503,504],{},"Unable to resolve service for type 'Microsoft.Extensions.Logging.ILoggerFactory' while attempting to activate 'Web.Startup'. – ",[155,505,506],{},"Exception\n",[129,508,509],{},"the startup constructor use to look like public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)",[129,511,512,513,518],{},"new to ASP.NET Core 3 it is no longer possible to inject ILogger in Startup.cs and Program.cs (Reference: ",[163,514,517],{"href":515,"target":166,"rel":516},"https:\u002F\u002Fgithub.com\u002Faspnet\u002FAnnouncements\u002Fissues\u002F353",[168],"Github",")",[129,520,521,522,527],{},"Another ",[163,523,526],{"href":524,"target":166,"rel":525},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fazure\u002Fazure-monitor\u002Fapp\u002Filogger#capture-ilogger-logs-from-startupcs-and-programcs-in-aspnet-core-apps",[168],"reference"," to this change specifically calls this out",[129,529,530,531],{},"Changes with ASP.NET Core 3 to Program.cs \u002F Startup.cs\nReference: ",[163,532,535],{"href":533,"target":166,"rel":534},"https:\u002F\u002Fandrewlock.net\u002Fexploring-the-new-project-file-program-and-the-generic-host-in-asp-net-core-3\u002F",[168],"Andrew Lock",[172,537,538],{},"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":21,"searchDepth":36,"depth":36,"links":540},[],"2019-12-09T20:51:35.746Z","Moving from ASP.NET Core 2 to ASP.NET 3 (Migration) there were a number of 'things' I picked up and decided I would document as I moved through the application.  New Program.cs and Startup.cs changes, new logging configuration changes, and default ASP.NET Core tips included.",{},"\u002Farticles\u002Faspnet-core-3-things-i-learned-pro-tips-migration-to-aspnet-core-3",{"title":205,"description":542},"articles\u002Faspnet-core-3-things-i-learned-pro-tips-migration-to-aspnet-core-3",[186],"w0iFgfavvdV8-1UR0gCTw4qVYXmyAzFa1CYkep7Rz8M",{"id":550,"title":551,"author":552,"body":553,"createdAt":640,"description":641,"extension":179,"img":7,"meta":642,"navigation":181,"path":643,"seo":644,"stem":645,"tags":646,"updatedAt":640,"__hash__":647},"articles\u002Farticles\u002Fhttpclient-saga--related-noteslinks.md","HttpClient Saga and Related Notes Links","[object Object]",{"type":9,"value":554,"toc":638},[555,570,586,589,600,603,618,621,624,631],[12,556,557,558,561,562,566,567],{},"On ",[155,559,560],{},".Net Full framework",", you can control the number of outgoing client connections by setting ",[163,563,565],{"href":564},"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. ",[155,568,569],{},"It is 2 by default.",[12,571,557,572,575,576,580,581,585],{},[155,573,574],{},".Net Core",", you can set it by changing ",[163,577,579],{"href":578},"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 ",[163,582,584],{"href":583},"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,587,588],{},"References:",[12,590,591,595,596,598],{},[163,592,594],{"href":564,"target":166,"rel":593},[168],"ServicePointManager"," ",[151,597],{},[163,599,579],{"href":578},[12,601,602],{},"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,604,605,595,610,595,612,614,615,617],{},[163,606,609],{"href":607,"target":166,"rel":608},"https:\u002F\u002Faspnetmonsters.com\u002F2016\u002F08\u002F2016-08-27-httpclientwrong\u002F",[168],"YOU'RE USING HTTPCLIENT WRONG AND IT IS DESTABILIZING YOUR SOFTWARE",[151,611],{},[151,613],{},"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. ",[151,616],{},"Due to these issues, the HttpClientFactory was created.",[12,619,620],{},"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,622,623],{},"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,625,626],{},[163,627,630],{"href":628,"target":166,"rel":629},"http:\u002F\u002Fanthonygiretti.com\u002F2018\u002F09\u002F06\u002Fhow-to-unit-test-a-class-that-consumes-an-httpclient-with-ihttpclientfactory-in-asp-net-core\u002F",[168],"How to unit test a class that consumes an HttpClient with IHttpClientFactory in ASP.NET Core?",[12,632,633],{},[163,634,637],{"href":635,"target":166,"rel":636},"https:\u002F\u002Fcodereview.stackexchange.com\u002Fquestions\u002F227596\u002Fsimple-httpclient-usage-for-integration-tests-in-net-core",[168],"Integration Testing",{"title":21,"searchDepth":36,"depth":36,"links":639},[],"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.",{},"\u002Farticles\u002Fhttpclient-saga-related-noteslinks",{"title":551,"description":641},"articles\u002Fhttpclient-saga--related-noteslinks",[186],"l1pMNA9gO17s0hmcoHaNRdtKD9yGrQyXApQIDK9aZKI",1781574765248]