BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News .NET 10 Preview 3: C# 14 Extension Members, ASP.NET Core State Persistence and Other Improvements

.NET 10 Preview 3: C# 14 Extension Members, ASP.NET Core State Persistence and Other Improvements

Listen to this article -  0:00

Last week, the .NET Team announced the third preview release of .NET 10. It brings several updates across the .NET Runtime, SDK, libraries, C#, ASP.NET Core, Blazor, .NET MAUI, WPF, Windows Forms, and more. This release introduces powerful new features to improve developer productivity, application performance, and flexibility.

In C# 14, notable improvements have been made to extension members. These members now support static methods, instance properties, and static properties, expanding the functionality of extensions. A new extension block syntax has been introduced, allowing developers to define extension methods and properties within a block that exposes the receiver to its contained members.

public static class Extensions
{
    extension(IEnumerable<int> source) 
    {
        public IEnumerable<int> WhereGreaterThan(int threshold)
            => source.Where(x => x > threshold);

        public bool IsEmpty
            => !source.Any();
    }
}


Additionally, null-conditional assignment is introduced, enabling property or field assignments only when the containing instance exists, simplifying code and reducing the need for explicit null checks.

ASP.NET Core has also seen notable enhancements. One of the key additions is a declarative model for persisting state from components and services. By using the SupplyParameterFromPersistentComponentState attribute, developers can now persist state during prerendering and load it automatically when the component renders interactively.

@page "/movies"
@inject IMovieService MovieService

<PageTitle>Movies</PageTitle>

<h3>Movies</h3>

@if (MoviesList == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <QuickGrid Items="MoviesList.AsQueryable()">
        <PropertyColumn Property="@(m => m.Title)" Title="Title" Sortable="true"  />
        <PropertyColumn Property="@(m => m.ReleaseDate)" Title="Release Date" Sortable="true" />
        <PropertyColumn Property="@(m => m.Genre)" Title="Genre" Sortable="true" />
        <PropertyColumn Property="@(m => m.Price)" Title="Price" Sortable="true" />
    </QuickGrid>
}

@code {
    [SupplyParameterFromPersistentComponentState]
    public List<Movie>? MoviesList { get; set; }

    protected override async Task OnInitializedAsync()
    {
        MoviesList ??= await MovieService.GetMoviesAsync();
    }
}

Following, Blazor WebAssembly apps now support referencing fingerprinted static web assets, improving cache management and versioning. Also, the response streaming for HttpClient is enabled by default in Blazor WebAssembly, optimizing memory usage when handling large responses. Other changes include the renaming of an app context switch and the introduction of server-sent events (SSE), which allows for real-time event streaming over HTTP connections, and more.

In .NET MAUI, the third preview release includes some significant updates. The ListView, Cell, and TableView controls have been deprecated, with their removal planned for a future release. Fullscreen video playback in Android WebViews is now possible, and a new Geolocation.IsEnabled property allows for easier checking of the geolocation service status.

Furthermore, a CancellationToken can now be passed to WebAuthenticator.AuthenticateAsync, providing greater control over authentication processes. Additionally, various performance improvements have been made, including optimizations to PropertyMapper and CollectionView rendering, resulting in faster application performance.

For developers working with WPF, the release introduces updates focused on improving performance and quality. Fluent style changes have been implemented, and performance optimizations ensure smoother user interfaces.

Also, for those interested in Windows Forms, this release brings quality improvements to various controls and runtime performance enhancements, ensuring that both frameworks are aligned with the latest .NET 10 updates.

Entity Framework Core 10 Preview 3 introduces improvements for working with Azure Cosmos DB for NoSQL. The model evolution process has been simplified, particularly as reported, when adding required entity properties.

EF Core now automatically assigns default values to required properties when no data is present in the document, eliminating the need for manual workarounds. Additionally, small improvements have been made in logging, including redacting inlined constants when sensitive logging is disabled, and better handling of extension loading.

This release also includes improvements in .NET for Android, iOS, Mac Catalyst, macOS, and tvOS. Android development has seen quality improvements, build performance enhancements, and experimental runtime updates. On the iOS side, support for Xcode 16.3 Release Candidate is included, along with further quality improvements.

For developers interested in further details and other changes, the full release notes are available, offering an in-depth look at the third preview of .NET 10.

About the Author

BT