What's New for ASP.NET Core and Blazor in Final Preview of .NET Core 3.0
Improved gRPC functionality is just one many new improvements in the ASP.NET Core component of .NET Core 3.0 Preview 9, the last step before the entire .NET Core 3.0 platform hits general availability in about three weeks.
Many Microsoft-centric developers were up in arms about the company's decision to abandon Windows Communication Foundation (WCF) -- part of the traditional .NET Framework -- in the move to.NET Core in favor of other mechanisms such as gRPC (Google's open source take on remote procedure call systems).
Microsoft earlier this year said, "If you are a remoting or WCF developer and want to build a new application on .NET Core, we would recommend either ASP.NET Core Web APIs or gRPC (Google RPC, which provides cross platform and cross programming language contract based RPCs)."
To that end, the final .NET Core 3.0 preview boosts gRPC functionality in the ASP.NET Core component. Preview 9 sports a new client API for gRPC and features support for async streams in streaming gRPC responses.
"To improve compatibility with the existing Grpc.Core implementation, we've changed our client API to use gRPC channels," said Daniel Roth, principal program manager for ASP.NET, in a Sept. 4 blog post. "The channel is where gRPC configuration is set and it is used to create strongly typed clients. The new API provides a more consistent client experience with Grpc.Core, making it easier to switch between using the two libraries."
Furthermore, Roth said, "gRPC streaming responses return a custom IAsyncStreamReader type that can be iterated on to receive all response messages in a streaming response. With the addition of async streams in C# 8, we've added a new extension method that makes for a more ergonomic API while consuming streaming responses."
- Render content using a specific layout
- Routing decoupled from authorization
- Route to components from multiple assemblies
Other improvements in Preview 9 listed by Roth include:
- Blazor event handlers and data binding attributes moved to Microsoft.AspNetCore.Components.Web: "In this release we moved the set of bindings and event handlers available for HTML elements into the Microsoft.AspNetCore.Components.Web.dll assembly and into the Microsoft.AspNetCore.Components.Web namespace."
- Render multiple Blazor components from MVC views or pages: "We've reenabled support for rendering multiple components from a view or page in a Blazor Server app. To render a component from a .cshtml file, use the Html.RenderComponentAsync(RenderMode renderMode, object parameters) HTML helper method with the desired RenderMode."
- Smarter reconnection for Blazor Server apps: "Blazor Server apps are stateful and require an active connection to the server in order to function. If the network connection is lost, the app will try to reconnect to the server. If the connection can be reestablished but the server state is lost, then reconnection will fail. Blazor Server apps will now detect this condition and recommend the user to refresh the browser instead of retrying to connect."
- Utility base component classes for managing a dependency injection scope: "In ASP.NET Core apps, scoped services are typically scoped to the current request. After the request completes, any scoped or transient services are disposed by the dependency injection (DI) system. In Blazor Server apps, the request scope lasts for the duration of the client connection, which can result in transient and scoped services living much longer than expected."
- Razor component unit test framework prototype: "We've started experimenting with building a unit test framework for Razor components. You can read about the prototype in Steve Sanderson's Unit testing Blazor components – a prototype blog post."
- Helper methods for returning Problem Details from controllers: "Problem Details is a standardized format for returning error information from an HTTP endpoint. We've added new Problem and ValidationProblem method overloads to controllers that use optional parameters to simplify returning Problem Detail responses."
All of the above and more is detailed in the blog post and the release notes.
The official general availability release of .NET Core 3.0 is scheduled for the online virtual event, .NET Conf, to be held Sept 23-25.
David Ramel is an editor and writer for Converge360.