David and friends has a great repository filled with examples of “broken patterns” in ASP.NET Core applications. It’s a fantastic learning resource with both markdown and code that covers a number of common areas when writing scalable services in ASP.NET Core. Some of the guidance is general purpose but is explained through the lens of writing web services. Here’s a few great DON’T and DO examples, but be sure to Star the repo and check it out for yourself! This is somewhat advanced stuff but if you are doing high output low latency web services AT SCALE these tips will make a huge difference when you’re doing a something a hundred thousand time a second! DON’T - This example uses the legacy WebClient to make a synchronous HTTP request. public string DoSomethingAsync() DO - This example uses an HttpClient to asynchronously make an HTTP request. static readonly HttpClient client = new HttpClient(); Here’s a list of ASP.NET Core Guidance. This one is fascinating. ASP.NET Core doesn’t buffer responses which allows it to be VERY scalable. Massively so. As such you do need to be aware that things need to happen in a certain order - Headers come before Body, etc so you want to avoid adding headers after the HttpResponse has started. DON’T - Add headers once you’ve started sending the body. app.Use(async (next, context) => DO - Either check if it’s started before you send the headers: app.Use(async (next, context) => Or even BETTER, add the headers on the OnStarting call back to guarantee they are getting set. app.Use(async (next, context) => There’s a ton of great guidance around async programming. If you are returning something small or trivial, like a simple value, DON’T Task<>: public class MyLibrary DO use ValueTask<> as this example not only doesn’t use an extra threads and avoids heap allocation entirely: public class MyLibrary There’s a ton of good learning over there so go check it out! https://github.com/davidfowl/AspNetCoreDiagnosticScenarios Sponsor: Make login Auth0’s problem. Not yours. Provide the convenient login features your customers want, like social login, multi-factor authentication, single sign-on, passwordless, and more. Get started for free. © 2021 Scott Hanselman. All rights reserved. ASP.NET Core Diagnostic Scenarios published first on http://7elementswd.tumblr.com/ via Tumblr ASP.NET Core Diagnostic Scenarios
0 Comments
Leave a Reply. |
About UsIf you want to keep up with the latest in web design, you have to be willing to study and learn on an ongoing basis. If you are a web developer or web designer, you’ll find a lot of useful tutorials and code snippets collection here. Furthermore, we also discuss more general topics of web design and how the role of a web designer has evolved over the years.
|