BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News ASP.NET Core Updates in .NET 8 Preview 3: Native AOT Support and More

ASP.NET Core Updates in .NET 8 Preview 3: Native AOT Support and More

Recently Microsoft released .NET 8 Preview 3. This new release contains many new improvements to ASP.NET Core, such as support for native AOT, server-side rendering with Blazor, rendering Razor components outside of ASP.NET Core, sections support in Blazor or monitoring Blazor Server circuit activity. 

In .NET 8 Preview 3, native AOT support for ASP.NET Core was added. Thanks to that, it is possible to publish an ASP.NET Core application with native AOT, creating a standalone application that is compiled ahead of time (AOT) into native code. Publishing and deploying a native AOT application can reduce the following things such as disk size, memory demand and startup time. 

Microsoft developers launched a simple ASP.NET Core API application to compare the differences in application size, memory usage, runtime and CPU load published with and without native AOT. Publishing the application as a native AOT improves start-up time and application size. In the experiment, start-up time was reduced by 80% and application size by 87%. These and other metrics are available on Microsoft's public benchmarking dashboard.

However, not all features and libraries in ASP.NET Core are compatible with native AOT. The .NET 8 platform represents the beginning of work to include native AOT in ASP.NET Core, with an initial focus on including support for applications using Minimal APIs or gRPC and being deployed in cloud-native environments. A table showing the compatibility of ASP.NET Core features with the native AOT is attached in the article with the announcement of ASP.NET Core updates in .NET 8 Preview 3.

This preview version also adds initial support for server-side rendering using Blazor components. This is the start of the Blazor unification work to enable the usage of Blazor components for all web UI needs, client-side and server-side. Blazor components are available for server-side rendering without the need for any .cshtml files. The framework will discover Blazor components with routing support and configure them as endpoints. There are no WebAssembly or WebSocket connections and no necessity to load any JavaScript. Each request is handled separately by the Blazor component for the corresponding endpoint.

The work to enable server-side rendering with Blazor components made it possible to render Blazor components outside the context of an HTTP request. Razor components can be rendered as HTML directly into a string or stream regardless of the ASP.NET Core hosting environment. This is helpful in scenarios where you want to generate HTML fragments.

Another point related to Blazor is the addition of the SectionOutlet and SectionContent components. They provide support for identifying outlets for content to be filled in later. Sections are often used to define placeholders in layouts that are then populated by specific pages. Sections are referenced by either a unique name or a unique object identifier.

Moreover, it is now an option to monitor inbound circuit activity in Blazor Server applications using the new CreateInboundActivityHandler method in CircuitHandler. Inbound circuit activity is any activity sent from the browser to the server, such as user interface events or JavaScript-to-.NET inter-operational calls.

The improvements to ASP.NET Core received positive feedback from the community. .NET developers left many comments under the release announcement. They especially appreciated the focus on performance and AOT compilation. There was also a question from Ömer Kaya about the availability of Blazor United in .NET 8. Daniel Roth, a principal program manager at Microsoft, answered:

The Blazor United effort is really a collection of features we’re adding to Blazor so that you can get the best of server & client-based web development. These features include: Server-side rendering, streaming rendering, enhanced navigations & form handling, adding client interactivity per page or component, and determining the client render mode at runtime. We’ve started delivering server-side rendering support for Blazor with .NET 8 Preview 3, which is now available to try out. We plan to deliver the remaining features in upcoming previews. We hope to deliver them all for .NET 8, but we’ll see how far we get.

About the Author

Rate this Article

Adoption
Style

BT