Skip to content
Katabench
Try free

The Layer Skip

Medium About 30 min Free, no account needed

A controller reaches past the application layer straight into infrastructure for the order total. Route the call back through the middle layer with a port the application owns; a thin pass-through that still touches infrastructure only moves the smell, it doesn't remove it.

The brief

You've inherited an orders module built as a strict layered stack: Presentation -> Application -> Infrastructure -> Domain. It compiles and the totals are correct, but Orders.Presentation.OrderController.GetTotal constructs a SqlOrderRepository from Orders.Infrastructure and reads it directly.

Presentation is allowed to call Application, and Application is allowed to call Infrastructure, but Presentation must never reach past Application straight into Infrastructure. That's a layer skip: the controller routes around the middle layer, so the middle layer can no longer enforce a rule, swap the data source, or be tested in isolation. The architecture rules flag two edges at once: Presentation depends on Infrastructure, and Presentation skips Application to get there.

The obvious move is to push the repository call down a level: wrap it behind a quick pass-through and have the controller call that. Try it and you'll find it isn't that simple. The skip is a symptom of a deeper problem (the controller can only reach the total through a concrete type), and the naive relocation just moves the smell into the layer below, where a different rule is waiting.

Your job

Route the order total back through the application layer without changing the response. Same inputs, same numbers.

  • Give Orders.Application a seam it owns, a repository port (interface), and expose the total through the service.
  • Have the concrete repository in Orders.Infrastructure implement that port, depending inward.
  • Make Orders.Presentation depend only on Orders.Application: drop the infrastructure using and the direct new SqlOrderRepository().
  • Wire the concrete repository in Solution (the composition root).

How it's graded

Your submission must (1) still return the same totals and (2) satisfy every architecture rule: presentation must not depend on infrastructure, presentation must not skip application to reach infrastructure, and the application layer may depend only on itself and the domain.

A thin pass-through that still news up the repository only relocates the dependency: it clears the skip but leaves the application layer reaching down into infrastructure, so a third rule turns red. Only inverting the dependency (a port the middle layer owns, the concrete injected from the composition root) turns them all green at once.

How it is graded

You work across multiple files, and architecture rules turn the design boundaries into executable feedback.

C# architecture exercises →

Related guides

What it practices

Layered architecture
Keep transport, wire formats and versions at the edge and route calls through each layer.
Dependency inversion
Point dependencies at abstractions the core owns, never at outer mechanisms.

Related katas