ASP.NET MVC Implementation
The original case study — transforming an MVC controller where technical flags drove business behavior into semantic intent contracts with immutable governance.
The Anti-Pattern
Technical flags like isExecutive and analysisDepth drove business behavior. HTTP method names determined document types. The result: identical 486,337-byte PDFs for fundamentally different content types.
// Technical flags driving business logic - WRONG
public async Task<ActionResult> GetQuickReport(int id)
{
var report = await _service.GenerateReport(id, isExecutive: true);
return Json(report);
}Semantic Intent Solution
Document semantics drive behavior. The SemanticIntentProcessor derives intent from observable document properties — title content, user role, request context — not technical flags.
// Document semantics driving behavior - CORRECT
var semanticIntent = SemanticIntentProcessor.DeriveFromRequest(request);
var protectedIntent = new ProtectedSemanticIntent(semanticIntent);
var report = await _service.GenerateReportAsync(id, protectedIntent);Deriving Intent from Observable Properties
The processor examines what can be directly observed about the document — its title, the requesting user's role, and the request context — to determine semantic intent.
public static SemanticIntent DeriveFromRequest(DocumentRequest request)
{
var title = request.DocumentTitle.ToLowerInvariant();
var userRole = request.UserRole ?? string.Empty;
var context = request.RequestContext?.ToLowerInvariant() ?? string.Empty;
var documentType = DetermineDocumentType(title, context);
var audience = DetermineAudience(userRole);
var contentDepth = DetermineContentDepth(documentType, audience);
return new SemanticIntent
{
DocumentType = documentType,
ContentDepth = contentDepth,
Audience = audience,
Format = DeterminePresentationFormat(audience),
PreservesOriginalMeaning = true
};
}Immutable Governance
The ProtectedSemanticIntent wrapper enforces semantic contracts at runtime. If an executive summary is created with detailed depth, the governance layer throws — fail-fast, not fail-silent.
public ProtectedSemanticIntent(SemanticIntent intent)
{
_intent = intent ?? throw new ArgumentNullException(nameof(intent));
ValidateSemanticContract(_intent);
}
private static void ValidateSemanticContract(SemanticIntent intent)
{
// Executive summaries must be Overview depth
if (intent.DocumentType == DocumentType.ExecutiveSummary &&
intent.ContentDepth != ContentDepth.Overview)
{
throw new SemanticContractViolationException(
"Semantic Rule Violation: Executive summaries require Overview depth");
}
}