LyraLearn AI Learning Platform
Exams
← Module 6 Β· Layered Architecture
🎧 Listen

Cross-Cutting Concerns

Validation, logging, caching, transactions β€” every feature needs them, no feature owns them. In a large codebase the danger isn't doing these things badly; it's doing them five different ways. This lesson is about the standard mechanisms and about picking one per concern.

The core four

Where the code hooks in

Three mechanisms, in order of preference:

Rule of thumb: request-level β†’ middleware or global filters; MVC-level β†’ filters; domain-level β†’ decorators or explicit service code. Base-controller inheritance and copy-pasted try/catch blocks are the mechanisms to retire.

Consistency is the feature

On a ten-year codebase, the second way of doing anything is a bug factory: half the actions logged, two cache key formats, validation that runs on some paths. When you join a team, find the established pattern for each concern and follow it β€” even if you'd have chosen differently. Propose changes as migrations with an owner, not as a sixth pattern. Boring and uniform beats clever and varied everywhere that operations, audits, and 2 a.m. debugging are real.

🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.