Design patterns are essential for creating maintainable and reusable code in .NET. Whether you’re a seasoned developer or just starting out, understanding and applying these patterns can greatly improve your coding efficiency and overall development process. In this post, we’ll take a look at the most important design patterns in .NET, and provide examples of how they can be implemented.
1. The Singleton Pattern
The Singleton Pattern The singleton pattern is used...
далее...
Prerequisites: VSCode and .Net 7 installed. Don't need to copy the code, GitHub link provided in the end.
Open up a terminal in VSCode or any IDE of your choice, run:
dotnet new console
2 files will appear, default Program.cs and .csproj named according to your folder:
Now let's create a file called OpenAIResponse.cs and start filling in the objects.
Main response object
Text response and usage objects
We will use these objects to translate the open...
далее...
What is pagination
So you may have already used this one, but you may be wondering what this pagination 😀. So as in figure 1, pagination helps you break a large number of datasets into smaller pages. For example, a storybook contains 1000 pages. Why does it have 1000 pages instead of 1? To ease the reading. Same thing in here as well. Imagine you are dealing with a dataset that...
далее...
C# AngleSharp tutorial shows how to parse HTML in C# with AngleSharp library.
The library can also parse SVG, MathML, or XML.
AngleSharp GitHub: https://github.com/AngleSharp
Document Object Model (DOM) is a standard tree structure, where each node contains one of the components from an XML structure. Element nodes and text nodes are the two most common types of nodes. With DOM functions we can create nodes, remove nodes, change their contents, and traverse...
далее...
We are going to discuss the Unit of Work design pattern with the help of a generic repository and step-by-step implementation using .NET Core 6 Web API.
Agenda
Repository Pattern
Unit of Work
Step-by-step Implementation
Prerequisites
Visual Studio 2022
SQL Server
.NET Core 6 SDK
Repository Pattern
The repository pattern is used...
далее...
Exception Handling is one of the important topics in Software Development. Exception means mainly run-time errors that occur at the time of execution of your application. The developer needs to handle that exception otherwise the application will be terminated.
Every developer has their own way of handling the errors in their code. Some of them are quite comfortable with having a try-catch block in their code and return system exception message....
далее...
Here’s the simple step-by-step guide that will teach you how to build and code a generic repository.
There are oodles of design patterns.
Some of these design patterns are floating about on antique blogs full of mad logic. They’re ridiculous enough to make the entire modern cloud rub its belly in roars of laughter.
Other design patterns are worth their dough.
And one of these is the repository pattern.
Of all the design patterns that...
далее...
New and old ways of creating your own exceptions in dotnet with C# 11 and .NET 7.
Let’s talk about building custom exceptions in C# code and why you’d want to do that. We’ll cover the traditional way as well as a newer way you might want to do this using the required keyword in C# 11.
Exception management in dotnet is quite versatile by default with try / catch / throw...
далее...
This article will look at the differences between static and readonly C# fields. Basically, a static readonly field can never be replaced by an instance of a reference type. In contrast, a const constant object cannot be replaced by a new one. You will learn what the difference is and how to use inline initialization with readonly fields. Ultimately, this article will help you write better code.
Readonly prevents a field...
далее...