Anti-Pattern: Schizophrenic Architecture
Description
The "Schizophrenic Architecture" occurs when a codebase cannot decide on a single data access strategy, leading to a mix of conflicting patterns within the same logical layer (or even the same method).
In WepNG_BO, this manifests as Controllers arbitrary choosing between:
- Direct Entity Framework Access: Instantiating
WEPV2DataContextdirectly and querying DbSets. - Service Layer Access: Instantiating
ComponentServices(e.g.,CenterComponentService) to perform actions.
Evidence
- Direct Access:
CatalogueController.Indexusesdb.Catalogues.Include(...). - Service Access:
CenterController.Indexusesnew CenterNGComponentService(...). - Mixed Mode:
CenterControllermethods often mixdb.Find()with service calls.
Impact
- Transaction Scope Ambiguity: If a controller opens a transaction via the Service, but then reads/writes using its own
dbcontext, data consistency is not guaranteed. - Testing Impossibility: We cannot mock the Data Access because it's hardcoded in the Controller (
new WEPV2DataContext()). - Cognitive Load: Developers must check every method to see "how" it talks to the DB.
Remediation
- Strict Layering: Controllers MUST mostly talk to Services/Handlers (Query or Command).
- Dependency Injection: Never
new DbContext()in a Controller. - Refactoring Rule: When touching a Controller, if it has
db.Something, move that logic to a Request Handler or Service.