Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News ASP.NET Core in .NET 8 Preview 4: Blazor Streaming, Form Handling, Native AOT, Identity API and More

ASP.NET Core in .NET 8 Preview 4: Blazor Streaming, Form Handling, Native AOT, Identity API and More

The latest release of .NET 8 Preview 4 brings significant improvements to ASP.NET Core. Notable enhancements include Blazor's streaming rendering and form handling, expanded support for form binding in minimal APIs, Native AOT compilation for improved performance, enhanced authentication and authorization with Identity API endpoints, and the addition of metrics for application monitoring.

The first noteworthy area of improvement is reserved for Blazor, with the latest preview release of .NET 8, a significant enhancement has been made to Blazor's server-side rendering (SSR) capabilities. With the introduction of streaming rendering, developers can now stream content updates on the response stream when using SSR with Blazor. This feature allows developers to render pages with placeholder content while async operations are executed, ensuring the main layout of the application is swiftly displayed. To enable streaming rendering, developers need to include the new Blazor script and apply the [StreamRendering(true)] attribute to the desired component.

Also, Blazor SSR now allows the utilization of Blazor components to handle form submissions, enabling server-side processing. To enable form submission handling from the server, developers can set up a model binding context using the CascadingModelBinder component, defining forms using the EditForm component and corresponding input components. However, while model binding and request data validation support is currently pending implementation, developers can manually handle request data using the FormDataProvider service.

Other notable Blazor-related changes include the support for using client-side routing to navigate to a specific HTML element on a page using standard URL fragments and Webcil packaging for Blazor WebAssembly apps.

Regarding the API authoring in ASP.NET Core, it has received attention as well. The framework now offers expanded support for form binding in minimal APIs, making it easier to handle and process form data. Furthermore, the API project template now includes a .http file, which allows developers to author and test HTTP requests directly within the project, simplifying the development workflow.

Native AOT (Ahead-of-Time) Compilation gained a significant amount of improvement in .NET 8 Preview 4. Among these advancements is automatic logging and exception handling for parameter binding failures in both runtime-generated and compile-time-generated minimal APIs, which simplifies error tracking and handling during parameter binding. Another significant addition is the inclusion of annotations on subsystem entry points to identify features incompatible with Native AOT. These annotations serve as warnings for developers, alerting them to potential issues with reliability. For example, invoking the AddControllers method in an application with Native AOT enabled will trigger a warning, indicating its lack of trim safety.

Other notable Native AOT-related changes include a reduced app size with configurable HTTPS support, the inclusion of the --aot flag in Worker Service templates for AOT publishing, additional default services in the slim builder, and JSON configuration changes in API templates.

In terms of authentication and authorization, it introduces MapIdentityApi<TUser>(), an extension method that adds new API endpoints for user registration and login (/register and /login). This enhancement aims to simplify the use of ASP.NET Core Identity for authentication in JavaScript-based single page apps (SPA) and Blazor apps. The JSON API endpoints provided by MapIdentityApi offer a more suitable solution for SPA apps and non-browser apps, replacing the default UI based on Razor Pages. Planned features for the identity API endpoints include support for two-factor authentication and email verification, as outlined in the ASP.NET Core GitHub repository.

Furthermore, significantly enhanced support for custom authorization policies has been introduced with the IAuthorizationRequirementData interface. This simplifies policy implementation by including the associated requirements in the attribute definition, reducing code complexity and improving maintainability. These improvements streamline the development workflow, offering developers increased flexibility in managing authorization within their applications.

Also, ASP.NET Core metrics have been enhanced to provide developers with better insights into the performance and behaviour of their applications. This update leverages the System.Diagnostics.Metrics API, offering an improved approach to data reporting and collection, supporting a range of measurements including counters, gauges, and histograms. Notably, the integration of metrics aligns with OpenTelemetry standards, ensuring seamless compatibility with the wider cloud-native ecosystem. Initially implemented for ASP.NET Core hosting, Kestrel, and SignalR, the future roadmap includes expanding metrics support to encompass additional APIs within the .NET framework.

Lastly, the comment section on the original release blog post has been buzzing with mixed reactions, as some users expressed disappointment regarding the significant time investment in Blazor, while others praised its productivity and effectiveness. For a comprehensive understanding of the various perspectives, it is highly recommended for users to explore the comment section and engage in the ongoing discussion.

About the Author

Rate this Article