This is the web version of my weekly newsletter, The .NET Stacks, originally sent to email subscribers on September 13, 2021. Subscribe at dotnetstacks.com to get this right away!
Happy Monday! Miss me? A few of you said you have, but I'm 60% sure that's sarcasm.
As you know, I took the last month or so off from the newsletter to focus on other things. I know I wasn't exactly specific on why, and appreciate some of you reaching out. I wasn't comfortable sharing it at the time, but I needed to take time away to focus on determining the next step in my career. If you've interviewed lately, I'm sure you understand ... it really is a full-time job. I'm happy to say I've accepted a remote tech lead role for a SaaS company here.
I'm rested and ready, so let's get into it! I'm trying something a little different this week—feel free to let me know what you think.
🔥 My favorite from last week
ASP.NET 6.0 Minimal APIs, why should you care?
Ben Foster
We've talked about Minimal APIs a lot in this newsletter and it's quite the hot topic in the .NET community. An alternative way to write APIs in .NET 6 and beyond, there's a lot of folks wondering if it's suitable for production, or can lead to misuse.
Ben notes: "Minimal simply means that it contains the minimum set of components needed to build HTTP APIs ... It doesn’t mean that the application you build will be simple or not require good design."
"I find that one of the biggest advantages to Minimal APIs is that they make it easier to build APIs in an opinionated way. After many years building HTTP services, I have a preferred approach. With MVC I would replace the built-in validation with Fluent Validation and my controllers were little more than a dispatch call to Mediatr. With Minimal APIs I get even more control. Of course if MVC offers everything you need, then use that."
In a similar vein, Nick Chapsas has a great walkthrough on strategies for building production-ready Minimal APIs. No one expects your API to be in one file, and he shows practical ways to deal with dependencies while leveraging minimal API patterns. Damian Edwards has a nice Twitter thread, as well. As great as these community discussions are, I really think the greatest benefit is getting lost: the performance gains.
đź“… Community and events
Increasing developer happiness with GitHub code scanning
Sam Partington
If you work in GitHub, you probably already know that GitHub utilizes code scanning to find security vulnerabilities and errors in your repository. Sam Partington writes about something you might not know: they use CodeQL—their internal code analysis engine—to protect themselves from common coding mistakes.
Here's what Sam says about loopy performance issues: "In addition to protecting against missing error checking, we also want to keep our database-querying code performant. N+1 queries are a common performance issue. This is where some expensive operation is performed once for every member of a set, so the code will get slower as the number of items increases. Database calls in a loop are often the culprit here; typically, you’ll get better performance from a batch query outside of the loop instead."
"We created a custom CodeQL query ... We filter that list of calls down to those that happen within a loop and fail CI if any are encountered. What’s nice about CodeQL is that we’re not limited to database calls directly within the body of a loop―calls within functions called directly or indirectly from the loop are caught too."
You can check out the post for more details and learn how to use these queries or make your own.
More from last week:
- Simon Bisson writes about how to use the VS Code editor in your own projects.
- The Netflix Tech Blog starts a series on practical API design and also starts writing about their decision-making process.
- The .NET Docs Show talks about micr0 frontends with Blazor.
- For community standups, Entity Framework talks about OSS projects, ASP.NET has an anniversary, .NET MAUI discusses accessibility, and Machine Learning holds office hours.
🌎 Web development
How To Map A Route in an ASP.NET Core MVC application
Khalid Abuhakmeh
If you're new to ASP.NET Core web development, Khalid put together a nice post on how to add an existing endpoint to an existing ASP.NET Core MVC app. Even if you aren't a beginner, you might learn how to resolve sticky routing issues. At the bottom of the post, he has a nice checklist you should consider when adding a new endpoint.
More from last week:
- Ben Foster explores custom model binding with Minimal APIs in .NET 6.
- Thomas Ardal debugs System.FormatException when launching ASP.NET Core.
- Jeremy Morgan builds a small web API with Azure Functions and SQLite.
- Ed Charbeneau works with low-code data grids and Blazor.
- Scott Hanselman works with a Minimal API todo app.
🥅 The .NET platform
Using Source Generators with Blazor components in .NET 6
Andrew Lock
When Andrew was upgrading a Blazor app to .NET 6, he found that source generators that worked in .NET 5 failed to discover Blazor components in his .NET 6 app because of changes to the Razor compilation process.
He writes: "The problem is that my source generators were relying on the output of the Razor compiler in .NET 5 ... My source generator was looking for components in the compilation that are decorated with [RouteAttribute]
. With .NET 6, the Razor tooling is a source generator, so there is no 'first step'; the Razor tooling executes at the same time as my source generator. That is great for performance, but it means the files my source generator was relying on (the generated component classes) don't exist when my generator runs."
While this is by design, Andrew has a great post underlying the issue and potential workarounds.
More from last week:
- Mark Downie writes about his favorite improvements in .NET 6.
- Sergey Vasiliev writes about optimizing .NET apps.
- Paweł Szydziak writes cleaner, safer code with SonarQube, Docker, and .NET Core.
- Sam Basu writes about how to develop for desktop in 2022, and also about developing for .NET MAUI on macOS.
- Paul Michaels manually parses a JSON string using System.Text.Json.
- Johnson Towoju writes logs to SQL Server using NLog.
- Andrew Lock uses source generators with Blazor components in .NET 6.
- Rick Strahl launches Visual Studio Code cleanly from a .NET app.
- Jiřà Činčura calls a C# static constructor multiple times.
â›… The cloud
Minimal Api in .NET 6 Out Of Process Azure Functions
Adam Storr
With all this talk about Minimal APIs, Adam asks: can I use it with the new out-of-process Azure Functions model in .NET 6?
He says: "Azure Functions with HttpTriggers are similar to ASP.NET Core controller actions in that they handle http requests, have routing, can handle model binding, dependency injection etc. so how could a 'Minimal API' using Azure Functions look?"
More from last week:
- Damien Bowden uses Azure security groups in ASP.NET Core with an Azure B2C identity provider.
- Jon Gallant works with the ChainedTokenCredential in the Azure Identity library.
- Adam Storr uses .NET 6 Minimal APIs with out-of-process Azure Functions.
🔧 Tools
New Improved Attach to Process Dialog Experience
Harshada Hole
With the 2022 update, Visual Studio is improving the debugging experience—included is a new Attach to Process dialog experience.
Harshada says: "We have added command-line details, app pool details, parent/child process tree view, and the select running window from the desktop option in the attach to process dialog. These make it convenient to find the right process you need to attach. Also, the Attach to Process dialog is now asynchronous, making it interactive even when the process list is updating." The post walks through these updates in detail.
More from last week:
- Jeremy Likness looks at the EF Core Azure Cosmos DB provider.
- Harshada Hole writes about the new Attach to Process dialog experience in Visual Studio.
- Ben De St Paer-Gotch goes behind the scenes on Docker Desktop.
- Esteban Solano Granados plays with .NET 6, C# 10, and Docker.
🏗 Design, testing, and best practices
Ship / Show / Ask: A modern branching strategy
Rouan Wilsenach
Rouan says: "Ship/Show/Ask is a branching strategy that combines the features of Pull Requests with the ability to keep shipping changes. Changes are categorized as either Ship (merge into mainline without review), Show (open a pull request for review, but merge into mainline immediately), or Ask (open a pull request for discussion before merging)."
More from last week:
- Liana Martirosyan writes about enabling team learning and boost performance.
- Sagar Nangare writes about measuring user experience in modern applications and infrastructure.
- Neal Ford and Mark Richards talk about the hard parts of software architecture.
- Derek Comartin discusses event-sourced aggregate design.
- Steve Smith refactors to value objects.
- Sam Milbrath writes about holding teams accountable without micromanaging.
- Helen Scott asks: how can you stay ahead of the curve as a developer?
- Rouan Wilsenach writes about a ship / show / ask branching strategy.
- Jeremy Miller writes about integration Testing using the IHost Lifecycle with xUnit.Net.
🎤 Podcasts and Videos
- Serverless Chats discusses serverless for beginners.
- The .NET Core Show talks about DotPurple With Michael Babienco.
- The Changelog talks to a lawyer about GitHub Copilot.
- Technology and Friends talks to Sam Basu about .NET MAUI.
- Visual Studio Toolbox talks about Web Live Preview.
- The ASP.NET Monsters talk about new Git commands.
- Adventures in .NET talk about Jupyter notebooks.
- The On .NET Show migrates apps to modern authentication and processes payments with C# and Stripe.
Top comments (0)