Skip to content
Katabench
Try free

Config Is Infrastructure

Medium About 25 min Free, no account needed

The shipping core reads a framework configuration type directly, welding the domain to infrastructure. Invert it behind a core-owned options port, and don't just rename the framework wrapper into the core, which trips a second rule.

The brief

You've inherited a shipping module. The rule that decides what shipping costs (cartTotal >= freeOver ? 0 : 9.99) lives in Shipping.Core.RateCalculator, exactly where a domain decision belongs. But to read its one setting (the free-shipping threshold), the calculator reaches straight for Shipping.Framework.AppConfiguration, a framework configuration type (a stand-in for something like IConfiguration).

That's the leak. Configuration is cross-cutting infrastructure, not domain. By taking the framework config type as a constructor parameter, Shipping.Core carries a using Shipping.Framework: an outward dependency from the most stable layer in the system into a framework concern. The core can no longer be compiled or reasoned about on its own. Behaviourally it computes the same rates.

The architecture rules flag it: Shipping.Core must depend on nothing but itself and the BCL, and there is no port expressing the core's need. The obvious move is to wrap AppConfiguration in a tidy little options class inside the core and call it done. Try that and you'll find it isn't that simple. The symptom (a leaked dependency) is protecting you from a deeper one, and that wrapper trips a different rule.

Your job

Figure out why the core depends on the framework at all, then invert that dependency so the core owns the abstraction it needs, passing every architecture rule, not just the dependency one. The behavior must stay byte-for-byte identical: same cart totals in, same rates out.

  • Express the core's need as a core-owned port IShippingOptions and have RateCalculator read its threshold from that port (constructor injection).
  • Keep the framework config type out of the core: implement IShippingOptions in an adapter that lives outside Shipping.Core (e.g. a Shipping.Config namespace) and wraps AppConfiguration.
  • Wire the adapter in Solution (the composition root).

How it's graded

Your submission must (1) still return the same shipping rate and (2) satisfy every architecture rule shown in the results: the port must exist, Shipping.Core must depend only on itself, and no *Configuration role may sit in the core.

The "just wrap it in the core" move is a trap. A core-side *Configuration wrapper that still reads the framework type leaves the core depending on Shipping.Framework (the dependency rule stays red) and drops a framework role right into the domain (a second rule fires). Only an adapter outside the core, implementing a core-owned port, turns them all green.

How it is graded

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

C# architecture exercises →

What it practices

Infrastructure as adapters
Keep the ORM, clocks, caches, configuration and startup work out of the core as replaceable adapters.
Dependency inversion
Point dependencies at abstractions the core owns, never at outer mechanisms.

Related katas