Showing posts from February, 2024

ASP.NET Core: Implementing CQRS and MediatR pattern in ASP.NET Core API

In this article, we will see an implementation of the Command Query Responsibility Segregation (CQRS) pattern in ASP.NET Core API with MediatR.  In my earlier article , I have already explained the CQRS. In this article, we will focus on Mediator Pattern.  Mediator Pattern Mediator is a behavioral design pattern that reduces coupling between components of the program. This is achieved by using a special mediator object. This object decouples components by managing indirect communication across them. This pattern makes the application easy to extend, reuse, and modify individual components because they do not have any direct dependency across them. Figure 1, will provide a good idea of the Mediator pattern. Figure 1: The Mediator Pattern As shown in Figure 1, the Mediator object is responsible for listening to requests from each service object and passing them to the actual Handler object hence implementing the decoupling across the Services and Handlers. This helps to further maintain

ASP.NET Core 8: Create a API with ASP.NET Core to Perform CRUD Operations with MongoDB

In this article, we will see the use of MongoDB database client in ASP.NET Core API to perform CRUD Operations. In the categories of building data collections applications we need to use a large size NoSQL Database. The MongoDB database is one of the powerful NoSQL databases data offers the large scale data in the form of JSON documents. The data collection applications collect data from various front-end applications like We Apps, Mobile, Browser Apps, etc. Across all such applications we need to use powerful server-side data collection APIs those who will connect to MongoDB database easily and provide a simplified mechanism for performing CRUD Operations, the ASP.NET Core is such a powerful but an easy technology of building APIs for modern apps. The ASP.NET Core uses the MongoDB.Driver NuGet package that provides set of useful classes to access MongoDB database for performing CRUD operations. Figure 1 will provide an idea of implementation of the application. Figure 1: The ASP.NET C

Blazor with .NET 8: Creating a Reusable FormComponent in Blazor

Blazor is one of the great technologies for building interactive User Interfaces. This helps to create UI Components using C# that can run in the browser. Although there are various standard components already available, sometimes we need to create our own components as per the demand of the application. Thankfully, Blazor offers such a great facility using which we can create our own component.  In this article, we will see the approach of creating a reusable form component in Blazor. This component will accept an entity object as input and then it will generate the Form UI. Step 1: Open Visual Studio 2022 and create a new Blazor WebAssembly Standalone application. Name this application as  Blazor_Components . Step 2: In this Blazor project, add a new folder and name it Models . In this folder, add class files named Student, Employee, and PropertyMetadata where we will add code for classed named Student, Employee, and PropertyMetadata respectively.   Listing 1 shows the code for these

Microsoft Azure Storage Blob: Download multiple Blobs from the Azure Storage Blob Containers using SemaphoreSlim Class

Azure Blob Storage is the Object storage in the Cloud. This storage is optimized for storing massive amounts of unstructured data. We use the Blob storage for storing large-size files, images, videos documents, etc. The images or documents can be directly served to the browser. In this article, we will implement a simple .NET 8 Console Application to download multiple Blobs.  To download multiple Blobs we will be using the SemaphoreSlim class. This is one of the superb classes provided on .NET. This class is used to limit the number of threads  that can access a resource or pool of resources concurrently.  T he SemaphoreSlim Class in C# is recommended for synchronization within a single app.  A lightweight semaphore controls access to a pool of resources that is local to the application. With an instantiate of a semaphore, we can specify the maximum number of threads that can enter the semaphore concurrently.   When we want more control over the number of internal threads that can acce