What's New for ASP.NET Core & Blazor in .NET 7

New functionality for the ASP.NET Core web-dev component of .NET 7 starts out with several enhancements to Blazor, which lets Microsoft-centric web coders use their favorite programming language, C#, instead of JavaScript.

.NET 7 shipped this week, finally unifying separate components into one umbrella development platform that lets developers build all types of apps -- cloud, desktop, mobile, web, AI, IoT and more -- on the same Base Class Library (BCL), runtime and compilers, thus fulfilling Microsoft's long-delayed push toward "just one .NET going forward."

As part of the big release, Microsoft detailed what's new for ASP.NET Core, starting with Blazor, used to create Single Page Applications (SPA). For example, developers can now create Blazor custom elements to dynamically render Razor components from other SPA frameworks including Angular or React. For more on that, see the article, "Custom Blazor Elements No Longer Experimental in .NET 7 Preview 6."

Improvements were also made around WebAssembly (sometimes abbreviated as Wasm), the open source tech baked into client-side Blazor that allows for C# in browser-based web projects by turning C# code into executable assembly-like code.

Interacting with JavaScript code -- called interop -- was also improved. For one thing, a new workload was introduced for new experimental templates: wasm-experimental. ".NET 7 introduces a new low-level mechanism for using .NET in JavaScript-based apps," Microsoft explained in a September preview. "With this new JavaScript interop capability, you can invoke .NET code from JavaScript using the .NET WebAssembly runtime as well [as] call into JavaScript functionality from .NET without any dependency on the Blazor UI component model."

Dynamic authentication requests are also new. Developers can create them at runtime with custom parameters to handle advanced authentication scenarios in Blazor WebAssembly apps. For more on JavaScript interop and dynamic authentication requests (along with Blazor WebAssembly debugging tweaks), see the article, "WebAssembly Steals the ASP.NET Core Show in .NET 7 RC1."

Also, a .NET 7 release candidate let developers try out early-stage experimental WebAssembly multithreading -- which is actually supposed to be included with .NET 8 next year -- thanks to the aforementioned wasm-experimental workload. "The wasm-experimental workload now includes support for multithreaded .NET apps on WebAssembly using Web Workers," Microsoft said in an October preview. "This is a new .NET runtime capability. Multithreading support hasn't been integrated yet into Blazor WebAssembly apps (planned for .NET 8), but you can still try it out in preview form using the experimental WebAssembly Browser App template." For more on that, see the article, "No Need to Wait for .NET 8 to Try Experimental WebAssembly Multithreading."

In other new goodies, the Blazor WebAssembly project template in Visual Studio has a new UI construct that shows the progress of loading an app. The loading screen animation is implemented with two new CSS custom properties -- acting as variables -- that are now part of Blazor WebAssembly. They are used to show the percentage of app files loaded and the percentage of app files loaded rounded to the nearest whole number.

New Blazor Loading Page in Animated Action
[Click on image for larger, animated GIF view.] New Blazor Loading Page in Animated Action (source: Microsoft).

For more on that, see the article, "What's New for Blazor, ASP.NET Core in Latest .NET 7 Preview." And, speaking of Visual Studio, for more on the latest Visual Studio 2022 release, version 17.4, which shipped along with .NET 7, see the article, "Visual Studio 2022 17.4 Now Generally Available."

Speaking of templates, there are new ones for Visual Studio 2022:

  • Blazor Server App Empty: An empty project template for creating a Blazor server app that runs server-side inside an ASP.NET Core app and handles user interactions over a SignalR connection. This template does not have any content in it.
  • Blazor WebAssembly App Empty: An empty project template for creating a Blazor app that runs on WebAssembly and is optionally hosted by an ASP.NET Core app. This template does not have any content in it.

Empty Blazor Project Templates
[Click on image for larger view.] Empty Blazor Project Templates (source: Microsoft).

Microsoft this week explained other Blazor enhancements, including:

Concerning that last item, the lack of native AOT was a longstanding .NET Core issue, with Microsoft in 2020 publishing results of a survey indicating that the lack of AOT was keeping developers from using .NET Core more. Since then, the company has been introducing it in drips and drabs across various properties.

Does the lack of officially supported native AOT option prevent you from using .NET more?
[Click on image for larger view.] "Does the lack of officially supported native AOT option prevent you from using .NET more?" (source: Microsoft).

More about mixed-mode AOT, multithreading and more can be found in the article, ".NET 7 WebAssembly Plans: Mixed-Mode AOT, Multi-Threading, Web Crypto."

Meanwhile, Blazor Hybrid, allowing for native apps that can leverage web technologies like HTML and CSS for additional functionality, sees faster performance and improvements around security, along with minor tweaks like the ability to open external web pages in the browser. According to planning documentation, security tweaks were intended to address:

  • The need to define what are the threats here
  • Rogue-ish third-party component?
  • The need to look at the threat models for other native client platforms, e.g. WPF, because we will likely have some subset of the same concerns
  • The need to review guidance from docs of each native WebView component for any best practices
Mixing and Matching Native and Web UI
[Click on image for larger view.] Mixing and Matching Native and Web UI (source: Microsoft).

You can read more about all that in the article, "What's Coming for Blazor Hybrid in .NET 7."

Along with Blazor and WebAssembly, other parts of the ASP.NET Core web-dev framework that were improved include servers/runtime, minimal APIs, gRPC, SignalR and MVC. Early in the year, Microsoft outlined plans for those properties and more:

  • Performance: .NET 6 contained many performance improvements for ASP.NET Core, and we'll do work to make ASP.NET Core even faster and more efficient in .NET 7.
  • HTTP/3: HTTP/3 support shipped as a preview feature in .NET 6. For .NET 7, we want to finish it and make it a supported feature that's enabled by default. In future previews, you can expect to see advanced TLS features and more performance improvements in our HTTP/3 support.
  • Minimal APIs: Add support for endpoint filters and route grouping as core primitives for minimal APIs. Also simplify authentication and authorization configurations for APIs in general.
  • gRPC: We're investing in gRPC JSON transcoding. This feature allows gRPC services to be called like RESTful HTTP APIs with JSON requests and responses.
  • SignalR: Add support for strongly-typed clients and returning results from client invocations.
  • Razor: We'll make various improvements to the Razor compiler to improve performance, resiliency, and to facilitate improved tooling.
  • MVC: Improvements to endpoint routing, link generation, and parameter binding.
  • Orleans: The ASP.NET Core and Orleans teams are investigating ways to further align and integrate the Orleans distributed programming model with ASP.NET Core. Orleans 4 will ship alongside .NET 7 and focuses on simplicity, maintainability, and performance, including human readable stream identities and a new optimized, version-tolerant serializer.

As for what was actually included in the final GA release, see the nitty-gritty details in Microsoft's Nov. 8 post and corresponding release notes.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


Subscribe on YouTube