ASP.NET Core MVC Interview Question #130
Why should MVC controllers be kept thin?
Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced
Quick Interview Answer
A thin controller focuses on HTTP orchestration: receiving input, checking request-level validity, calling application services, and choosing an appropriate response. Business rules, complex workflows, and data-access logic should generally live in dedicated layers or services.
Detailed Explanation
A thin controller focuses on HTTP orchestration: receiving input, checking request-level validity, calling application services, and choosing an appropriate response. Business rules, complex workflows, and data-access logic should generally live in dedicated layers or services.
Thin controllers are easier to test, understand, reuse, and change. They also reduce duplication when the same business operation is needed from another entry point such as a background job or API.
Code Example
[HttpPost]
public async Task<IActionResult> Create(
ProductInputModel model,
CancellationToken token)
{
if (!ModelState.IsValid)
return View(model);
await _productService.CreateAsync(model, token);
return RedirectToAction(nameof(Index));
}