While I was working on a .NET WebApi Logging middleware component, I realized that I needed some unit tests to verify that the Logging middleware was actually working as intended. I started down the usual path of installing a mocking library in my test project so that I could mock the logger. But then I … Continue reading Using NullLogger and a FakeLogger in Your .NET Tests
Category: Coding Tips
Using the with Expression on Classes
Just today I learned that the with expression in C# is not limited to records. It can also be used with classes, as long as the class is defined with the with expression requirements. And what are the requirements to work with the with expression? Requirements for with expressions to work: The type must be … Continue reading Using the with Expression on Classes
Understanding await vs. ContinueWith in C# Async Programming
When it comes to asynchronous programming in C#, developers have powerful tools to make applications more responsive and efficient. By allowing long-running operations to execute in the background, we can keep the UI thread free for other tasks, resulting in smoother user experiences. Or when running those tasks on ASP.NET, the service can respond to … Continue reading Understanding await vs. ContinueWith in C# Async Programming
How to Make Internal Types Visible to Other Projects Using .csproj File
In many software development scenarios, especially when working with unit tests, you might encounter situations where you need to test internal types and methods within your code. However, internal members are, by default, inaccessible to other projects. The traditional approach to solving this problem in .NET is to make these internal types visible to specific … Continue reading How to Make Internal Types Visible to Other Projects Using .csproj File
Understanding C# Keywords
In C#, keywords play a crucial role in defining how your code behaves. They help in establishing various programming constructs like classes, methods, variables, and even asynchronous behavior in a structured and precise way. This article will explore some essential C# keywords, providing clarity on their purpose and usage. 1. sealed: Preventing Inheritance The sealed … Continue reading Understanding C# Keywords
Why Should I Care about Mutable vs. Immutable Types
In C#, classes and objects can be categorized as mutable or immutable based on whether their state can be changed after they are created. Understanding the distinction between mutable and immutable types is crucial for designing robust, maintainable, and performant applications. Mutable Classes Mutable classes are those whose state or data can be modified after … Continue reading Why Should I Care about Mutable vs. Immutable Types
UUID v7: Enhancing Sortable Unique Identifiers for Developers
.NET 9 brings an exciting new feature for developers: UUID v7. This new version of UUID integrates a timestamp into the traditionally random UUID structure, offering significant advantages for databases and other systems requiring sortable unique identifiers. It also still produces IDs that follow the GUID format, so they are compatible with other unique IDs … Continue reading UUID v7: Enhancing Sortable Unique Identifiers for Developers
Endpoint Explorer in Visual Studio
(Version: Visual Studio 17.6+) HTTP files are a popular feature in VSCode and were brought into Visual Studio too. Recently, I learned about another cool endpoints feature in Visual Studio called the Endpoints Explorer. This tool window lists all of the endpoints of your Web API project. You can find the Endpoints Explorer by going … Continue reading Endpoint Explorer in Visual Studio
Global Using Directives
In C# 10, a new feature was introduced that allows you to specify global using directives. This feature lets you define using directives that apply to all the files in your project, reducing the need for repetitive using statements in each file. This can be particularly useful for commonly used namespaces. How to Specify Global … Continue reading Global Using Directives
Creating Interactive Console Applications in C#
Console applications (or command line interfaces - CLI) have long been a staple for developers due to their simplicity and ease of use. However, with the right tools and techniques, you can build sophisticated console applications that are both interactive and user-friendly. Let's explore how to create advanced console applications in C# using Spectre.Console.Cli for … Continue reading Creating Interactive Console Applications in C#