The .NET Stacks #62: 👋 And we're back

This is the web version of my weekly newsletter, The .NET Stacks, originally sent to email subscribers on September 13, 2021. Subscribe at the bottom of the post 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:


🌎 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:


🥅 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:


⛅ 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:


🔧 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:


🏗 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:


🎤 Podcasts and Videos