ASP.NET Core MVC Interview Question #200

What senior-level principles should guide ASP.NET Core MVC production architecture?

Senior Practical MVC Scenarios & Production Architecture Senior Advanced

Quick Interview Answer

Design around clear responsibilities: controllers handle HTTP flow, ViewModels define UI contracts, application services coordinate use cases, the domain owns business rules, and infrastructure handles external concerns. Prefer explicit dependencies, server-side authorization, strong validation, safe error handling, and measurable behavior.

Detailed Explanation

Design around clear responsibilities: controllers handle HTTP flow, ViewModels define UI contracts, application services coordinate use cases, the domain owns business rules, and infrastructure handles external concerns. Prefer explicit dependencies, server-side authorization, strong validation, safe error handling, and measurable behavior.

Optimize from evidence rather than intuition. Use asynchronous I/O, efficient database queries, appropriate caching, concurrency controls, background processing, secure file handling, observability, and deployment-aware Data Protection. Most importantly, keep the architecture proportional to the problem: introduce patterns and infrastructure when they solve concrete maintainability, security, reliability, or scale requirements.

Code Example

[HttpPost]
[Authorize(Policy = "CanManageProducts")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(
    ProductEditInput model,
    CancellationToken token)
{
    if (!ModelState.IsValid)
        return View(model);

    var result = await _service.UpdateAsync(
        User, model, token);

    if (!result.Succeeded)
        return Forbid();

    return RedirectToAction(nameof(Index));
}