Skip to main content

Posts

๐Ÿš€Master User Authentication in .NET 8 Web API Email Confirmation, Password Reset, 2FA & Lockout with JWT & Identity๐Ÿ”

Part2️⃣ - Caching | ๐Ÿš€ Mastering Microservices: Using YARP as Your Ultimate API Gateway & Reverse Proxy! ๐Ÿ”—๐Ÿ’ก

  Memory Cache Service Description This code provides a robust implementation of an in-memory caching service using the IMemoryCache interface from the Microsoft.Extensions.Caching.Memory namespace. The implementation is divided into an interface and a concrete class to promote abstraction and dependency injection. IMemoryCacheService Interface The IMemoryCacheService interface defines the contract for the caching service, ensuring that any implementation of this interface will provide the following methods: SetCache : Parameters : string key : The unique identifier for the cached item. object value : The object to be stored in the cache. int expirationInSeconds : The time in seconds after which the cached item will expire. Description : This method stores a value in the cache with the specified key and sets an expiration time for the cached item. GetCache : Parameters : string key : The unique identifier for the cached item. Returns : string Description : This method retrieves the

Part1️⃣ - Configuring Yarp | ๐Ÿš€ Mastering Microservices: Using YARP as Your Ultimate API Gateway & Reverse Proxy! ๐Ÿ”—๐Ÿ’ก

  Description The BasicConfiguration class in the ApiGateway.Configurations namespace provides the configuration settings for YARP (Yet Another Reverse Proxy). This class defines the routing and clustering configurations required to direct API requests to appropriate backend services. Routes Configuration PRODUCT API Route ID : product-route Cluster ID : product-cluster Match : Configures the URL path pattern to route requests with paths starting with /api/product/{**catch-all} to the product-cluster . ORDER API Route ID : order-route Cluster ID : order-cluster Match : Configures the URL path pattern to route requests with paths starting with /api/order/{**catch-all} to the order-cluster . Clusters Configuration Product Cluster Cluster ID : product-cluster Destinations : A dictionary defining the destination for the product-cluster . It maps to the backend service located at http://localhost:5001 . Order Cluster Cluster ID : order-cluster Destinations : A dictionary defining the de

Struggling with Excel in .NET 8 Blazor?๐Ÿš€Learn how to Effectively Read & Display Excel File in Blazor Application๐ŸŒŸ

Reading Excel Files in a Blazor App This Blazor component allows users to upload and read Excel files, displaying the contents in an HTML table. It leverages the EPPlus library for reading Excel files and incorporates a custom file upload component from NetcodeHub . Key Features File Upload Component The component integrates NetcodeHubFileUpload , a custom file upload component designed to handle file uploads in Blazor applications. It is configured to accept only .xlsx files by setting the RequiredExtensions property to [".xlsx"] . The Multiple property is set to false , restricting the upload to a single file at a time. The ShowDisplay property is set to true , which likely displays a progress bar or some visual indicator during the upload process. The Notify event is hooked to a method called RetrieveFiles , which processes the uploaded file. Error Display Any errors encountered during

Part 6️⃣ - Create UnitTest | ๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ

  Unit Testing OrdersController in .NET 8 Web API with FakeItEasy and FluentAssertions - OrdersControllerTest.cs In this tutorial, we explore how to unit test the OrdersController in a .NET 8 Web API project. By leveraging the power of FakeItEasy for mocking dependencies and FluentAssertions for writing expressive assertions, we ensure that our controller behaves as expected. We'll cover various scenarios to validate the controller's actions, including retrieving client orders and order details. Here’s what we’ll cover: 1. Setting Up the Test Environment We'll start by configuring our test environment. Using FakeItEasy , we create mock instances of our service dependencies, and we initialize the OrdersController with these mocks. 2. Testing GetClientOrders Action Valid Client ID : We'll verify that when a valid client ID is provided, the controller returns an OK result with the expected list of orders. No Orders Found : We'll handle the scenario where no orders

Part 5️⃣ - Ocelot Gateway API๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ

Ocelot Configuration File - ocelot.json This configuration file sets up routes for an API Gateway using Ocelot. The gateway manages requests for three main services: Authentication, Product, and Order APIs. Here's a detailed description of each section: Authentication Routes Path : /api/authentication/{everything} Host : localhost:5000 Methods : GET, POST, PUT, DELETE Rate Limiting : Allows 1 request per 10 seconds. Product Routes Get All Products Path : /api/products Host : localhost:5001 Method : GET Caching : 60 seconds with custom header eCommerce-Caching-Control . Get Product By ID Path : /api/products/{id} Host : localhost:5001 Method : GET Caching : 60 seconds with custom header eCommerce-Caching-Control . Modify Products Path : /api/products/{everything} Host : localhost:5001 Methods : POST, PUT, DELETE Authentication : Bearer token required. Order Routes Get All Orders Path : /api/orders Host : localhost:5002 Method : GET Caching : 20 seconds with custom header eCommerce-C

Part 4️⃣ - JWT Authentication API |๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ

Entity Description - AppUser AppUser Class Description The AppUser class represents a user in the application, encapsulating various properties related to user identity, contact information, and roles. Here’s a detailed breakdown of each property: Id Type : int Description : A unique identifier for the user. Name Type : string? Description : The user's name. It is nullable, allowing the possibility of no name being provided. TelephoneNumber Type : string? Description : The user's telephone number. It is nullable. Address Type : string? Description : The user's physical address. It is nullable. Email Type : string? Description : The user's email address. It is nullable. Password Type : string? Description : The user's password for authentication. It is nullable. Role Type : string? Description : The role assigned to the user (e.g., Admin, User). It is nullable. DateRegistered Type : DateTime Description : The date and time when the user registered. It defaults to th

Part 3️⃣ - Order API |๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ

Domain Layer Order Entity The Order entity represents an order within the e-commerce system. It captures essential details related to a customer's purchase and is a core component of the Order API. Properties Id : Type: int Description: Unique identifier for the order. This serves as the primary key in the database. ProductId : Type: int Description: Identifier for the product associated with the order. This links the order to a specific product in the Product API. ClientId : Type: int Description: Identifier for the client who placed the order. This associates the order with a specific customer. PurchaseQuantity : Type: int Description: The quantity of the product purchased in the order. OrderedDate : Type: DateTime Description: The date and time when the order was placed. Defaults to the current UTC time when the order is created. Summary The Order entity is a crucial part of the Order API, encapsulating the data required to manage and process customer orders. It link

Part 2️⃣ - Product API |๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ

๐Ÿ›’ Build .NET 8 eCommerce Microservice ๐Ÿš€with API Gateway, Rate Limiting, Caching & more ๐Ÿงบ - [Part 2️⃣] Product Description This code defines the Product class within the ProductApi.Domain.Entities namespace. The Product class represents a product entity with properties commonly associated with products in an e-commerce application. Features Id : Represents the unique identifier for the product. It is an integer property and serves as the primary key for the product entity. Name : Represents the name of the product. It is a nullable string property, allowing the product name to be optional. Price : Represents the price of the product. It is a decimal property, ensuring accurate representation of the product's cost, including fractions of currency units. Quantity : Represents the quantity of the product available in stock. It is an integer property, indicating the number of units of the product that are available. Usage Data Representation : The Product class is used to rep