Hey Reader,
This week, I've got a new video for you about Blazor SSR. It's all about using static server-side rendering in Blazor without needing things like websockets or WebAssembly. It's a complete guide on creating, reading, updating, and deleting data. Plus, I've added a bonus tip about a neat feature in C# to make your code look better and easier to understand. Hope you enjoy it!
Check out this one-hour video where I dive into Blazor and .NET 8. You'll learn how to handle data - adding, viewing, changing, and removing it - using Blazor's static server-side rendering method.
When you're working with data in Blazor SSR, the ??= operator in C# can be really useful. It helps you set a value to something only if that thing doesn't already have a value. It's a simple way to check if something is empty and fill it if it is. Here's a quick look at how it works and why it's great for making your code cleaner and easier to read.
Let's look at how this operator works in practice. The basic syntax is as follows:
This translates to two scenarios:
variable
is not null, the code does nothing.variable
is null, it gets assigned the value
.Examples
To appreciate the elegance of this operator, let's compare two code snippets.
Traditional Approach (Without ??=):
Using the Null Coalescing Assignment Operator:
Notice how the latter approach reduces the code complexity and enhances clarity.
Why Use It?
Whether you are a beginner or an experienced C# developer, the ??=
operator is an invaluable addition to your coding toolkit.
Consider a scenario where you need to initialize a complex object but only if it hasn't been set up yet. The ??=
operator makes this task straightforward, ensuring your code remains clean and readable.
While this operator is powerful, it's crucial to use it wisely, though. Always prioritize clarity in your code over mere brevity.
Have you tried using this operator in your code? How did it go? Let me know!
π Your Turn! What are your thoughts on Blazor SSR in .NET 8? I'm keen to hear about your experiences.
A massive shoutout to our community and a special thanks to my Patrons for their unwavering support. Your contributions are the lifeblood of this newsletter and my YouTube channel.
Looking forward to our next coding adventure. Stay safe, and enjoy your coding journey! π»
Take care,
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...