Code Maze Author

Code Maze

This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.
Also find me here:



MY ARTICLES:

Serilog Rolling File Logging: Intervals and Retention

Pass rollingInterval to the file sink and Serilog starts a new file on that schedule: .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day) produces log20260824.txt, log20260825.txt, and so on. Two more options decide how long that stays manageable....

ModuleInitializer Attribute in C#

As a C# developer, you might have overlooked the ModuleInitializer attribute introduced in version 9 of the language. This attribute is a hidden gem in the extensive BCL APIs and designates a method that the runtime should first invoke when loading the assembly....

IdentityUser in ASP.NET Core: Add Custom Properties

IdentityUser gives us a user with a name, an email, a password hash and a lockout state, and no place to put a column of our own. The fix is to subclass it: ApplicationUser : IdentityUser, our properties on the subclass, and ApplicationUser everywhere the framework...

Techniques for Sorting a List in C#

In this article, we will explore different techniques for sorting a list. A common task we face as developers is the need to sort a collection of data. The C# language provides us with a variety of ways in which we can accomplish this task. To help us have a better...

Value vs Reference Types in C# – In Depth Guide

In this article, we will learn about the categories of C# data types. We will deep dive into the differences between value types and reference types, what are they and what's the behavior of each type when instantiated, compared, or assigned. It's important to...

Source Generators in C#

Traditionally, code generation in C# involved using external tools or templates to generate code before the compilation process, like the T4 template. However, with source generators, code generation becomes an integral part of the compilation itself. In this article,...

How to Merge Dictionaries in C#?

Dictionary<TKey, TValue> has no built-in method that merges dictionaries, so we merge them ourselves: with a foreach loop that copies every key-value pair into a new dictionary, or with LINQ methods such as Concat(), GroupBy(), ToLookup() and Union(). These...

NSubstitute: Effective Mocking in .NET

NSubstitute is a mocking library for .NET that reads like plain C#: Substitute.For<IEmailService>() creates the mock, service.IsValid(x).Returns(true) configures it, service.Received().Send(x) verifies it. No Mock<T> wrapper, no .Object property, no lambda...

XML Deserialization in C#: How to Deserialize XML

XML deserialization turns an XML document into a C# object. We describe the shape we expect as a class, hand the document to XmlSerializer, and get back an object with its properties filled in. Without a class to map onto, the alternative is reading and parsing an XML...

Saga Pattern With NServiceBus in C#

Navigating the world of distributed systems and microservices in C#? Then we should appreciate the combination of the Saga Pattern and NServiceBus. This powerful pairing provides us with an efficient solution for coordinating long-running, distributed transactions in...

Unable to Resolve Service for Type: How to Fix It in .NET

InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y' means the dependency injection container was asked to build Y, found a constructor parameter of type X, and had no registration for X. The full message looks like this,...

Scrutor in .NET: Assembly Scanning and Decoration

Scrutor adds two things missing from .NET's built-in dependency injection container: assembly scanning, which registers all our services in one line instead of dozens, and decoration, which wraps a registered service with logging, caching, or validation without...

How to Efficiently Randomize an Array in C#

In this article, we will look at how we can efficiently randomize an array in C#. We'll explore several ways of achieving that and then we'll compare the performance of each approach. [sc name="github"...

MediatR Publish and Send Methods

In this article, we are going to explore the key differences between the Publish and Send methods in MediatR, a powerful .NET library for component communication. [sc name="github"...

Required Parameters in Blazor WebAssembly

When we want to pass data in Blazor from a parent component to a child component, we use parameters. Parameters are defined on the component class with the Parameter attribute. If we define the parameter in the child component but don't pass a parameter from the...