Posts

Showing posts from May, 2026

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 ...

Mediator Pattern in .NET with MediatR

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 your own mediator, the M...