Posts

Four pillars of Object-Oriented Programming (OOP) in C#

   Inheritance  C# is an object-oriented programming (OOP) feature that allows one class to derive properties and behaviors from another class. It promotes code reusability, extensibility and establishes a natural hierarchical relationship between classes. Types of Inheritance C# directly supports the following inheritance forms: Single Inheritance: One class derives from one base class. Multilevel Inheritance: A class derives from another derived class. Hierarchical Inheritance: Multiple classes derive from a single base class. Multiple Inheritance (Through Interfaces): A class can implement multiple interfaces, achieving multiple inheritance indirectly, since C# does not allow multiple base classes Encapsulation Encapsulation is one of the core principles of object-oriented programming (OOP). It refers to the practice of binding data (fields) and the methods that operate on that data into a single unit, while restricting direct access to some components. This ensures ...
1.  The Mediator pattern The Mediator pattern in .NET Core is a behavioral design pattern that reduces coupling between components by forcing them to communicate indirectly through a central "mediator" object . Instead of classes having direct references to each other, they send messages to the mediator, which then routes them to the appropriate handlers.  Why Use It? Decoupling: Objects don't need to know about each other's existence or implementation details. Slim Controllers: In ASP.NET Core, it keeps API controllers thin by moving business logic into separate "handler" classes. Maintainability: Centralizing communication logic makes it easier to modify or extend individual components without ripple effects. CQRS Support: It is the standard way to implement Command Query Responsibility Segregation (CQRS) , where "Commands" (writes) and "Queries" (reads) are handled separately The Standard Implementation: MediatR While you can build...

Scenario bases Question

https://chatgpt.com/c/6a0d671d-37cc-8321-bc6c-4a4b80d6a293 1. The Custom Pipeline Scenario : "Your application needs to intercept every incoming request to check for a specific custom header. If missing, it must redirect to a maintenance page without hitting the controller. How do you implement this? For this scenario, Middleware is the correct choice — not an Action Filter. Why? Because the requirement is: Inspect every incoming HTTP request Check for a custom header Short-circuit the pipeline early Redirect before MVC/controllers execute That is exactly what ASP.NET Core middleware is designed for. Why Middleware is Better Than Action Filters Middleware Runs Earlier in the Pipeline Middleware executes before the request reaches MVC . Pipeline flow: Request ↓ Middleware ↓ Routing ↓ MVC / Controllers ↓ Action Filters ↓ Controller Action So if the header is missing: Middleware can stop processing immediately No controller instantiation No ...