ASP.NET Core .NET 8 Preview 4 New Features and Updates

ASP.NET Core .NET 8 Preview 4 New Features and Updates
May 16, 2023
9 minutes read

Yes, you are reading correctly, the latest news about ASP.NET Core has been released! We’re about to dive into all the exciting new features and updates aimed at providing you a more efficient and enjoyable development experience

The ASP.NET Core development team has been working hard on these latest features that have been released in this latest Preview. Blazor enhancements, performance improvements and much more! Get ready to explore the ins and outs of API authoring, Native AOT and all the shiny new metrics at your fingertips!

Blazor

Streamlining SSR with Blazor Components

Do you fancy fast-loading server-side Blazor pages? As of .NET 8, streaming content updates to client-side is possible with SSR (Server-Side Rendering)! With async tasks running in parallel and using placeholders, your pages will load faster than ever. Let’s find out how!

This is the new line of code you should add to your Blazor project:

Loading code snippet...

After that:

Loading code snippet...

In this way the process that follows is that while the asynchronous tasks are running, “Loading…” will be displayed. When they complete their execution, the information will be passed to the client inside the DOM.

Mastering Form Posts in Blazor SSR

Exciting news! Now it will be easier to deal with form posts when it comes to SSR. Here’s how to start:

Create a model binding context with the CascadingModelBinder component in your main layout:

Loading code snippet...

Define a form in Blazor using the EditForm component and always remember to set the method attribute for form submission handling:

Loading code snippet...

Although model binding and validation features are yet to be introduced, this is still a fantastic improvement for Blazor users!

Named Element Routing in Blazor

Now, Blazor has released an extraordinary feature that allows client-side routing to specific HTML elements using URL fragments. No more endless scrolling or getting lost in your app – all thanks to URL fragment magic!

  • Just add an id attribute to your desired element
  • Blazor automatically scrolls to the element when the URL fragment matches its identifier

If you are wondering why use Named Element Routing in Blazor? Well, here’s a couple of compelling reasons:

  • Effortlessly guide users to what matters most in your app, without them manually scrolling a mile
  • Improve user experience with enhanced navigation capabilities
  • Boost the overall usability and perception of your app

Bye-Bye .dll Woes: Webcil Packaging for Blazor WebAssembly Apps

Are you tired of dealing with blocked .dll file downloads or .dll usage issues? Webcil packaging is here to save the day! Webcil removes native Windows execution content from .NET assemblies, putting an end to these frustrations.

Start by adding the WasmEnableWebcil property to your project file:

Loading code snippet...

Minimal APIs Now Support Form Binding

If you’re a fan of minimal APIs, you’ll be thrilled to hear that form binding for specific types is now possible without the assistance of the FromForm attribute. This update applies to IFormCollection, IFormFile and IFormFileCollection.

Here you can see the Microsoft example:

Loading code snippet...

Remember to protect your apps against XSRF attacks. This code sample will show you how to enable anti-forgery services in ASP.NET minimal APIs.

Boost Your API Development with

New API projects now come with an included .http file:

Loading code snippet...

Get ready to make the most of this supercharged API development experience!

Native AOT

Streamlined Logging and Exception Handling in Compile-time Minimal APIs

Through the Request Delegate Generator, you can now add automated logging and exception handling to your compile-time minimal APIs.

Microsoft sure knows how to cater to developers!

bytehide.com

Take a look at these API endpoints activated by <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>:

Loading code snippet...

In this example, in the case that you send any request but you do not provide the name parameter to /hello, you’ll experience a BadHttpRequestException:

Loading code snippet...

The same applies here, an unparsable birthDate parameter in the /age endpoint will prompt another exception:

Loading code snippet...

ASP.NET Core Metrics

Now, Microsoft has shown improvements in ASP.NET Core metricts, thanks to the awesomeness of System.Diagnostics.Metrics. Huh, isn’t that cool?

Now, you might be wondering, “sure, that sounds great, but what’s in it for me?” Hold on to your hats because these new metrics are a game-changer, especially compared to those old-timer event counters. Here’s a taste of what’s on offer with Metrics:

New Measurement Types

Get ready for a whole new level of measurement goodness! Say hello to counters, gauges, and histograms. Imagine all the possibilities with these new tools at your disposal!

Enhanced Multi-Dimensional Value Reporting

Who doesn’t love adding a little extra dimension to their life? With enhanced multi-dimensional value reporting, you’ll dive deeper into understanding your application’s performance. It’s like having X-ray vision into your app, but you know… without any side effects.

Compatibility with Cloud-Native Ecosystems

Raise your hand if you love OpenTelemetry! This impressive addition ensures that your ASP.NET Core metrics play nicely with your favorite cloud-native ecosystem. Finally, no more awkward silos and barriers, just pure harmony!

So, fellow C# enthusiasts, are you excited yet to dive into these shiny new ASP.NET Core metrics? I know I am! These new features are not just mind-blowing, but also insanely practical for optimizing our applications. Don’t let your app’s performance leave you guessing – embrace the Metrics revolution and optimize your way to success!

Conclusion

As we wrap up this overview of ASP.NET Core .NET 8 Preview 4’s new features and updates, you can now see how it’s poised to transform the way you build and monitor web applications, all while ensuring a smooth and pleasant development experience.

With the enhancements to Blazor, minimal APIs, Native AOT and newly introduced metrics, you can be confident that you’ll have everything you need to create performant and scalable applications with ease. Don’t hesitate to explore these features even further and integrate them into your projects today. Surf’s up!

You May Also Like

Optional Parameters in C#: What You Need to Know

Optional Parameters in C#: What You Need to Know

Programming in C# often requires flexibility and simplicity ...

What is Lock Keyword in C#? Main Usages

What is Lock Keyword in C#? Main Usages

IndexUnderstanding the C# Lock Keyword Can’t tell a lock fro...

Enumerate in C#: Detailed Explanation

Enumerate in C#: Detailed Explanation

Desperate to decode the mystery that is enumeration in C#? I...

Creating a JSON Class in C#: Detailed Guide

Creating a JSON Class in C#: Detailed Guide

In the world of application development, manipulation of dat...

Static Class in C#: How to Use It?

Static Class in C#: How to Use It?

Hello there, future C# aficionado! It’s time to roll down th...

DateTime Formatting in C#: Dev Guide

DateTime Formatting in C#: Dev Guide

Have you ever gotten frustrated handling dates and times in ...

Leave a reply

Loading comment form...