We have been using the ILogger interface provided by .NET Core, but do you know how to leverage BeginScope for our benefit? Let’s explore how BeginScope helps us harness log scoping effectively. Let’s examine a sample transaction API in a minimal API project and see how one would typically write logs as the transaction flows…
We’ll revisit the same example from our previous article on the Option<T> monadโa clean way to handle potential failures without drowning in null checks. By now, you’ve seen how the Option<T> monad lets us chain operations smoothly, sidestepping those tedious null inspections at every step. It’s like assembling a puzzle where missing pieces gracefully halt…
When to Use SingleOrDefault vs FirstOrDefault? Many developers are familiar with the FirstOrDefault() method in LINQ for C#. However, there’s also SingleOrDefault(). What’s the key difference between them? And why might you choose one over the other instead of always sticking with FirstOrDefault()? Both methods work on collections that implement the IEnumerable<T> interface, allowing you…
Let’s take an example of calculating the delivery estimate given a username. Letโs walk through that journey together and see how a mysterious functional programming concept called a monad can turn nightmare-level null-checks spaghetti into clean, fluent, and safe code. Note: The code snippets here are simplified for clarity and flowโthey might not compile straight…