CRUD with Blazor in .NET 8 🔥 Video & Code Inside 🚀


Hey Reader,

This week we're diving deep into Blazor via .NET 8, focusing on mastering CRUD operations using the fresh render modes—Auto, Server, WebAssembly, and even no render mode for static server-side rendering via stream rendering. Yep, that's a mouthful of new capabilities for you!

CRUD with Blazor in .NET 8 Video 🔥

No sweat, I've got you sorted. This week's video walks you through each render mode and demonstrates how to flawlessly execute CRUD operations, complete with persistence via Entity Framework and SQL Server Express.

video preview

Key Code Snippets 🖥️

If you're more of a code-first person, here's a sneak peek at the essential code sections. With the latest Blazor Web App template in Visual Studio 2022 Preview, selecting Auto or WebAssembly render modes gifts you two projects—Server and Client. The Server project comes fully equipped for Web API tasks, including the ability to add API controllers, which is vital for using server-side services in your client project.

Say you've crafted a simple game library entity:

Along with the requisite Entity Framework boilerplate:

Watch Your Steps!

Have you set all this up in the Server project? Ah, but what if you need to access your Game Entity or services from the Client project? To solve this, I shifted everything to a separate Class Library:

You'll notice that this setup closely resembles the older Blazor WebAssembly ASP.NET Core Hosted template from .NET 7.

The Nitty-Gritty

To call server logic from your client app, web service calls are still the way to go. Dependency Injection comes to the rescue, allowing us to implement the IGameService interface differently for the client:

Remember to register your GameService and HttpClient on both client and server ends.

Client:

Server:

And, of course, don't forget the new controller on the server:

I get it; this might feel overwhelming at first. But trust me, once you get your bearings, the new .NET 8 features will feel like second nature. I'm also working on a video that compares the .NET 7 and .NET 8 versions of a Blazor WebAssembly app. So stay tuned!

To grab the complete code, watch the video or head to my Patreon page for the repo download.


💌 Got questions or topics you're curious about? Just hit 'reply'—your input is priceless. A massive shoutout to everyone for making this community what it is! 🙌 Special thanks to my Patrons—your support fuels this newsletter and my YouTube channel.

Until our next coding journey, stay well and happy coding! 💻

Patrick


Patrick God

Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.

Read more from Patrick God

Hey Reader, Tired of factories and messy if-else logic in your projects? Since .NET 8, Keyed Services make it easy to handle multiple implementations. No more clutter - just clean, scalable code. In my new video, you’ll see how to dynamically pick services using a key and write code that’s easy to extend. It’s a fresh, modern approach to dependency injection that’ll have you rethinking how you design your APIs. 👉 Watch the video here Wishing you a fantastic start to the new year filled with...

video preview

Hey Reader, You sit down to write an API, and before you know it, you’re knee-deep in controllers, attributes, and boilerplate. Sound familiar? What if you could skip all that and still build a fully functional API - fast? That’s where Minimal APIs in .NET come in. They’re clean and lightweight and make building APIs feel like a breeze. In my latest video, I show you how to set up endpoints step by step and structure everything neatly so your code stays easy to read and scale. No fluff - just...

video preview

Hey Reader, Ever sort through your books or video games to find the best one? 🎮 What if you could do that in your code - fast and easy? That’s what LINQ is all about! With LINQ, you can:✅ Find the stuff you want✅ Sort them by year, rating, or price✅ Filter to get only your favorites And the best part? No more long, boring loops! In my latest video, I show you:🔹 How to use LINQ step by step🔹 What Lambda Expressions are (and why they’re super simple)🔹 Real examples with a video game list you’ll...