The .NET Stacks #58: 📃 6 things about .NET 6 Preview 6

This week, we talk about .NET 6 Preview 6, Visual Studio 2022, and abstracting away Kubernetes.

Dave Brock
Dave Brock

Welcome to another wonderful week. I just learned you can put a timestamp in Notepad by hitting F5. I saw this by reading a blog post from 2002. How's your Monday?

Here's what we have going on in #58:

  • One big thing: 6 things about .NET 6 Preview 6
  • The little things: Visual Studio 2022 Preview 2, abstracting Kubernetes
  • Last week in the .NET world

One big thing: 6 things about .NET 6 Preview 6

Last week, the .NET team rolled out .NET 6 Preview 6. Richard Lander has the main blog post.  Dan Roth writes about ASP.NET Core updates, Jeremy Likness updates us on EF Core 6, and David Ortinau covers .NET MAUI. Preview 6 is the second to last preview release of .NET 6. It appears to be a smaller release, with Preview 7 being bigger, as it's the last preview release.  .NET 6 will end up with seven preview releases, then two RC releases (the latter of which should come with go-live licenses).

The releases will be winding down soon, as Richard Lander says: "We’ll soon be addressing only the most pressing feedback, approaching the same bug bar that we use for servicing releases. If you’ve been holding on to some feedback or have yet to try .NET 6, please do now. It’s your last chance to influence the release."

If you want the full details, you can check out the links above—as for me, I'd like to highlight six things that caught my eye.

Sync-over-async thread performance. The sync-over-async pattern—which means using synchronous functionality asynchronously—is a common source of performance degradation and thread starvation. A new change in Preview 6 will improve the rate of default thread injection when the only blocking work on the thread pool is sync-over-async.

New functionality for working with parameters in ASP.NET Core. The ASP.NET Core team released two new features that help when working with components in ASP.NET Core.

The first involves required Blazor component parameters. You do this by using a new [EditorRequired] attribute, like this:

[EditorRequired]
[Parameter]
public string Title { get; set; }

This functionality is enforced at design time and when building—it's important to note it isn't enforced at runtime and won't guarantee the value of the parameter won't be null.

The next feature now supports optional parameters for view component tag helpers in ASP.NET Core. With this update, you no longer need to specify a value for an optional parameter as a tag helper attribute.

WebSocket compression. ASP.NET Core now supports WebSocket compression. This can yield tremendous performance benefits with comes with a ton of caveats. It's disabled by default because enabling it over encrypted connections can make your app subject to attacks. As such, you should only enable it when you know sensitive information isn't being passed around. If that isn't clear enough, the setting is called DangerousEnableCompression. No, seriously.

Minimal API improvements. We've talked about .NET 6 Minimal APIs quite a bit—so much you're probably sick of me talking about them. Even so, the team keeps building them out and Preview 6 brings some enhancements.

First, you can now integrate those APIs with OpenAPI (Swagger) support. You can do this using dependency injection (DI) or middleware. Here's an example using the DI method:

builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Description = "My Swagger", Version = "v1" });
});

Second, you can now inject services into the [FromServices] attribute. Previously, you needed to do something like this:

app.MapGet("/movies", async ([FromServices] MovieDbContext db) =>
{
    return await db.Movies.ToListAsync();
});

 And now it's this:

app.MapGet("/movies", async (MovieDbContext db) =>
{
    return await db.Movies.ToListAsync();
});

Pre-convention model configuration. From Preview 6 of EF Core, they've released pre-convention model configuration. From the announcement, Jeremy Likness says it's part of "finding ways to enhance model building so that it can more efficiently figure out what is an entity type and what is not." As more types are mapped, it can be painful to exclude types as entity types (and bringing all that overhead into a model) and reverting types from being entity types in certain situations.

You can now use a ConfigureConventions override to avoid the hassle of configuring every entity. In Jeremy's example, if you want to always store strings as byte arrays, you can use the override instead:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
  {
      configurationBuilder.Properties<string>()
          .HaveConversion<byte[]>()
          .HaveMaxLength(255);

      configurationBuilder.IgnoreAny<INonPersisted>();
  }

.NET MAUI packaged as workload installation. With .NET 6, Xamarin is merging into the .NET Multi-platform UI (MAUI). MAUI is aiming to be a cross-platform framework for creating mobile and desktop apps with C# and XAML. I don't mention it much here in the newsletter for two reasons—I can't speak about it intelligently because I have no experience with it, and I'm allergic to XAML. The last time I opened a XAML file I got a fever and was in bed for three days.

Even so, there's a lot of great work going into it, and Preview 6 marks the first time MAUI will be shipped as a workload installation. Like the rest of .NET, you can use SDK workloads to enable specific workloads. In MAUI's case, the team is introducing maui, maui-mobile, and maui-desktop workloads, and soon Visual Studio 2022 will include these workloads in the installer.

MAUI is getting close to feature-complete for .NET 6. In this release, the team is rolling out gesture recognizers, clipping region enhancements, and native alerts. Check out the announcement to learn more.


The little things: Visual Studio 2022 Preview 2, abstracting Kubernetes

Since we're on the topic of previews, Visual Studio 2022 Preview 2 is out. Preview 2 is fully localized and ships with over a dozen language packs.

In this update, VS 2022 includes new "Live Preview" experiences with XAML and web apps, which allows you to kiss goodbye to the ancient-feeling recompile-and-run workflow. They are also touting a new Web Live Preview, to allow you to speed up your workflow, with instant updates when working with CSS or data controls. (I suppose we're happy to have it, even if it's an expected feature from modern IDEs these days.) Lastly, this update introduces Force Run, a way to run your app to a specific point that ignores other breakpoints or exceptions. (If you work on C++, check out the post. C++ isn't a .NET language, so I don't write about it here.)


When I see click-baity articles with headlines like Why Developers Should Learn Kubernetes, I can't help but cringe. Thankfully, the article is better than the headline suggests—but even so, it's a lot to suggest developers should know the ins and outs of pods, containers, networking, DNS, and load balancing. There's a difference between asking developers to Shift Left, and making them become SRE experts.

Kubernetes gets a lot of grief: it can be extreme overkill and it incurs a steep learning curve. Even so, containerization (and orchestrating these containers) is here to stay, but we should be providing developers with more abstractions over Kubernetes to make it a more PaaS-like experience. Microsoft is working on their part, and don't be surprised to see Azure (and other clouds) make investments in this space.


🌎 Last week in the .NET world

🔥 The Top 4

📢 Announcements

📅 Community and events

🌎 Web development

🥅 The .NET platform

⛅ The cloud

📔 Languages

🔧 Tools

🏗 Design, testing, and best practices

🎤 Podcasts

🎥 Videos

.NET Stacks