Layer skipping happens when a component bypasses an intervening layer—for example, when a presentation component calls the database directly instead of going through the service layer. section 4.3.2
The tempting shortcut
A product controller that queries a SQL repository directly may skip service rules such as filtering discontinued products or checking permissions. It also ties the UI to the database choice, making a later change harder. section 4.3.2
Listing 4.3 Violating Downward Dependency (Skipping Layers)
// Presentation Layer (Controller)
public class ProductController : Controller
{
private SqlProductRepository _repo = new SqlProductRepository(); #A
public IActionResult GetAll()
{
var products = _repo.GetProductsSql(); #B
return View(products);
}
}See a controller querying a SQL repository directly, bypassing the intervening layer. section 4.3.2
Keep dependencies flowing downward through adjacent layers. The application layer can coordinate the work and return data upward; it need not make infrastructure call the UI. section 4.3.2
