Posts

Showing posts with the label .NET Core

CORS (Cross-Origin Resource Sharing) in .NET

CORS stands for Cross-Origin Resource Sharing. It is a security feature that allows web pages from one domain to access resources (such as APIs) on another domain. When a web page attempts to access a resource on a different domain, the browser will send a CORS request to the server hosting the resource. The server can then choose to allow or deny the request based on the domain of the requesting web page. CORS is important because it helps to prevent malicious attacks, such as cross-site request forgery (CSRF) and cross-site scripting (XSS). By enforcing same-origin policies, CORS helps to protect users from unauthorized access to their sensitive data. We use CORS to enable cross-domain communication between web pages and APIs. Without CORS, web pages would only be able to communicate with APIs hosted on the same domain. With CORS, we can make APIs available to web pages on other domains, allowing for a more flexible and dynamic web. CORS is co...

HTTP and grPC Communication protocols used in Microservices

Microservices architecture is an approach to building distributed systems that involves breaking down a large application into smaller, loosely coupled services that communicate with each other through APIs. There are several communication protocols used in microservices architecture, including HTTP and gRPC. HTTP: HTTP (Hypertext Transfer Protocol) is a widely used protocol for communication between web applications and servers. In microservices architecture, HTTP is used for communication between services as it's a well-established and reliable protocol that's widely supported. HTTP is simple and easy to use, and it supports a wide range of data formats like JSON, XML, and plain text, making it a popular choice for microservices communication. gRPC: gRPC is a modern, high-performance, open-source protocol for communication between microservices. It uses Google's Protocol Buffers as a data format, which is a language-neutral, platform-neu...

Tightly Coupled and Loosely Coupled in .NET Core with example

In .NET Core, tight coupling and loose coupling refer to the way software components are designed and connected to each other. Tight coupling in .NET Core means that two or more software components are highly dependent on each other, making it difficult to modify or replace one component without affecting the others. This can lead to maintenance and testing challenges, as well as reduced flexibility and scalability. Loose coupling in .NET Core, on the other hand, means that software components are designed to be independent and have minimal interdependence. This is achieved by using interfaces, dependency injection, and other techniques to reduce the direct dependencies between components. Loose coupling allows components to be more easily replaced, modified, or extended without affecting the rest of the system. Summary, loose coupling is generally preferred in .NET Core because it makes software more flexible, maintainable, and scalable. Advant...

Domain Driven Design (DDD) in .NET Core

Domain-Driven Design (DDD) is an approach to software development that emphasizes the importance of the business domain in the software design process. It is a set of principles and practices aimed at building software systems that are aligned with the business needs and requirements. The main idea behind DDD is to create a shared understanding of the domain model between the domain experts (business stakeholders) and the software developers. This is achieved by using a common language and a set of tools that allow for the domain model to be explicitly represented and manipulated in code. In DDD, the domain model is the central focus of the software design process. It is a representation of the core business concepts and rules that govern the behavior of the system. The domain model is expressed in code using object-oriented programming techniques, and it serves as the backbone of the software system. DDD also introduces several design patterns and ...

Configure the API gateway in Microservices Architecture with example in .NET Core

API Gateway in Microservices Architecture In a microservices architecture, an API Gateway is a layer that sits between clients and the microservices that provide the necessary functionalities. It acts as a single entry point for all client requests and handles communication between the clients and the underlying microservices. The API Gateway serves as a mediator between the client and the backend services. It receives incoming requests from clients and routes them to the appropriate microservice. It also handles authentication, authorization, load balancing, and other cross-cutting concerns such as rate limiting, caching, and request/response transformation. By providing a single entry point and a unified interface for clients, the API Gateway simplifies client access to the system and helps to decouple the client code from the underlying microservices. It also provides a central point for monitoring and logging of all the incoming requests, making it easier to identify and troublesho...

Aggregation and Association and Composition and Its differences with examples

 Aggregation, association, and composition are object-oriented programming concepts that define relationships between classes or objects. Here are their definitions and differences: 1. Aggregation: Aggregation is a relationship where one object has a reference to another object, but the referenced object can exist independently of the object that references it. The object that references the other is known as the container or owner, while the referenced object is known as the contained or member object. Here are a few examples of aggregation in C#: Example - 1 : A university has many departments, and each department has many students. In this case, the Department class is the container, and the Student class is the contained object. Here's an example code: public class Department {     public List<Student> Students { get ; set ; } } public class Student {     public string Name { get ; set ; } } Example - 2 : A car has an engine, and the engine can ...

Difference of High-Level Design (HLD) and Low-Level Design (LLD)

High-Level Design (HLD) and Low-Level Design (LLD) are software design concepts that are not specific to any programming language. However, to illustrate the differences between HLD and LLD, we can use C# programming language examples. Suppose we are designing a software system that involves creating a payment gateway application in C#.  Here are examples of HLD and LLD for this system: High-Level Design (HLD): Define the functional requirements of the payment gateway system, such as processing payment transactions, handling errors, and providing a user interface. Identify the non-functional requirements, such as performance, scalability, and security. Identify the key components of the payment gateway system, such as payment processing engine, database, user interface, and error handling. Create an architecture diagram that shows how these components will fit together to form the payment gateway system. In HLD, the focus is on defining the system's overall structure and architectu...

Clean Architecture in a C#

Clean Architecture is a software design pattern that separates the application into independent layers, where each layer has a specific responsibility and interacts with other layers through well-defined interfaces. The main goal of clean architecture is to create a flexible, testable, and maintainable software system. By following this architecture, we have created a flexible, testable, and maintainable software system. The domain layer is independent of any external dependencies and frameworks, making it easy to test and change without affecting other layers. The application layer contains the use cases or application-specific logic, which is decoupled from the infrastructure Here's an example of how to implement Clean Architecture in a C# project: 1. Domain Layer: This layer contains the business logic and domain-specific entities. It should be independent of any external dependencies and frameworks. C# ...

Implementing DIP (Dependency Inversion Principle) in .NET Core project

Dependency Inversion Principle (DIP) is one of the SOLID principles that states that high-level modules should not depend on low-level modules, instead both should depend on abstractions. In .NET Core, we can implement DIP using various techniques such as Dependency Injection, Inversion of Control (IoC), and Service Locator. Here's a simple example of how to implement DIP using Dependency Injection in a .NET Core project: By following below steps, we can implement DIP in our .NET Core project using Dependency Injection. 1. Define interfaces for the low-level modules (dependencies) that the high-level module needs to use. For example: public interface ILogger {     void Log( string message); } public interface IDataProvider {     string GetData(); } 2. Create implementations for these interfaces.  For example: public class FileLogger : ILogger {     public void Log( string message)     {         // cod...