Built-In Rate Limiting Middleware in ASP.NET Core
The rate limiting middleware has shipped since ASP.NET Core 7.0, and the code here runs on .NET 10. We configure it with builder.Services.AddRateLimiter(), put it in the pipeline with app.UseRateLimiter(), and attach a policy to an endpoint with the...
Represent the Relationship of Properties Using Property Mappings From AutoMapper
In this article, we'll take a look at what property mappings are and how to retrieve them from AutoMapper. AutoMapper is a free .NET library that streamlines object mapping, reducing manual coding to boost development speed and minimize the risk of errors....
Better Minimal APIs Endpoint Organization With Carter in ASP.NET Core
In this article, we'll look closely at the Carter library and how we can use it in our ASP.NET Core projects. Let's get started! What...
How to Check the Total Number of Items Defined in an Enum
In this article, we talk about enums and, more specifically, how to find the total number of items defined in the enum. But first of all, let's define an enum. [sc name="github"...
Baseline Styling in BenchmarkDotNet
In this article, we will learn how to set a baseline for our benchmark in BenchmarkDotNet and discuss styling the baseline results. As software developers, benchmarking the performance of our methods is a crucial part of our day-to-day activities. With the...
The Difference Between Invariance, Contravariance and Covariance in Generics in C#
In this article, we will explore the role, significance, usage, and impact of invariance <T>, contravariance <in T> and covariance <out T> in our C# generics programming. Generics in C# enable us to design flexible, reusable classes and methods,...
Introduction to Strawberry Shake and GraphQL in .NET
In this article, we'll get familiar with GraphQL and Strawberry Shake, a GraphQL tool that facilitates interaction with local and remote data. Subsequently, we will build an application using the .NET API, focusing on customers searching for available space in...
How to Use HttpOnly Cookie in .NET Core for Authentication and Refresh Token Actions
In this article, we will show you how to use HttpOnly Cookie in .NET Core apps to secure our JWT or JSON Web Tokens, when implementing the authentication and refresh token actions. [sc name="patreon-source-code"...
Fastest Way to Find and Extract a Number From a String in C#
This article will explore the quickest method to find and extract a number from a string in C#. We will discuss and implement different techniques for accomplishing this task. Subsequently, we will evaluate the performance of these techniques using the BenchmarkDotNet...
How to Detect if a Key is Pressed in a C# Console Application
We frequently read data from user input in our C# application. However, we sometimes need to detect a key press and continue the operation. In this article, we discuss how to detect if a key is pressed in a C# console application. By understanding the usage of these...
Improvements in the Using Directive for Additional Types in C#
The "using" directive in C# helps us reduce boilerplate code when referencing types and members that sit outside the context of our class. C# 12 further expanded on the using directive, allowing it to be used for additional types. In this article, we'll start by...
How to Test gRPC Services in ASP.NET Core
gRPC is a popular way to create fast and scalable API's in the .NET world. In this article, we explore how to test gRPC Services in .NET applications, and set up both unit and integration tests to ensure the reliability and performance of gRPC services. [sc...
How to Set a Default User-Agent on an HttpClient in C#
HttpClient sends no User-Agent header unless we add one. We can set it on a single HttpRequestMessage, or set it once on the client's DefaultRequestHeaders so that every request it sends carries the same value. We'll look at what the header holds first, then set it...
Restricting a Value Lifetime With the “scoped” Keyword in C#
In this article, we will discuss the scoped keyword in C#, explore its use case, and examine how it can be advantageous. The contextual keyword scoped in C# serves as a powerful tool for restricting the lifetime of a value. Employing the scoped modifier allows us to...
How to Validate File Upload Extensions in ASP.NET Core
In this article, we will see how we can validate file upload extensions and be certain that our applications are safe from malicious uploads. When receiving files uploaded by users, relying solely on file names to determine file types is risky. This is because we can...
Handling Circular References When Working With JSON in .NET
When working with JSON (JavaScript Object Notation) in .NET applications, developers often encounter challenges related to circular references, where objects circularly reference each other. In this article, we'll explore common scenarios involving circular...
The Best Way to Assign an Initial Value to Auto-Properties in C#
In this article, we will explore auto-properties and various ways to assign an initial value to it in C#. The C# programming...
How to Get the Number of CPU Cores in C#
Environment.ProcessorCount gives us the number of logical processors our process can use, and it works on every platform .NET runs on. For physical cores and processor sockets, we query WMI on Windows through the System.Management package. Knowing the difference...
Present a List of Files in a Directory With Directory Browsing in ASP.NET Core
In ASP.NET Core, directory browsing is a feature that allows a web application to present a list of files in a specified directory to the user. For security, however, directory browsing is disabled by default to prevent unauthorized users from accessing a website's...
GeneratedRegex in C#: Improve RegEx Performance in .NET
Source-generated RegEx moves the work of building a regular expression from run time to build time. We mark a partial method with the [GeneratedRegex] attribute, and the .NET SDK writes the matching code for us as plain C#. In our benchmark on .NET 10, it validated a...
Scale Your Services With Service-Oriented Architecture in .NET
In this article, we will discuss the Service-Oriented Architecture in .NET. We will cover what it is, how to implement it, how it differs from Microservice Architecture, and how we can use cloud computing platforms as a jump pad to quickly stand up services and...










