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!
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.
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.
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
Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.
Hey Reader, After 15 years of building web apps, I just recently discovered Vertical Slice Architecture. I know. I’m late to the party. But wow, this approach really changed how I think about structuring Blazor projects. So I decided to show you a simple, real-world example of how to use Vertical Slice Architecture in a Blazor Server app. 🎥 Watch the full tutorial now: In this new tutorial, you'll learn: ✅ How to structure your app with feature folders ✅ How to avoid overcomplicating things...
Hey Reader, In my last videos, we built a solid CRUD API using Vertical Slice Architecture, Minimal APIs, and Carter - super clean and modern. But there’s still one problem... 👉 What happens when a user sends empty or invalid data? In this new YouTube tutorial, I’ll show you how to fix that with: And yep, the full source code is free to download. Just check the link in the video description. If you’ve been enjoying this Vertical Slice series, this is a must-watch. It’s a simple upgrade that...
Hey Reader, If you're building apps with Blazor, you've probably asked yourself this: 👉 Should I use SSR, Blazor Server, or WebAssembly? It’s a common question - and I get it a lot. So I made a brand-new YouTube video walking you through how to choose the best one for your app. 🎥 Watch it here: If you're building a Blazor app or planning to do so soon, this should help clear up a lot of confusion. Let me know what you think, and feel free to reply if you have any questions. Take care, Patrick...