ASP.NET Core MVC Interview Question #169
What is an MVC convention?
Testing, AJAX/JavaScript Integration, Localization & Advanced MVC Senior Advanced
Quick Interview Answer
MVC conventions allow an application to customize model metadata, controller/action discovery, routing behavior, and other MVC configuration according to project-wide rules. Examples include application model conventions that modify controllers, actions, selectors, or route models during application startup.
Detailed Explanation
MVC conventions allow an application to customize model metadata, controller/action discovery, routing behavior, and other MVC configuration according to project-wide rules. Examples include application model conventions that modify controllers, actions, selectors, or route models during application startup.
Conventions can reduce repetitive attributes, but overly implicit conventions make an application harder to understand. Use them when the rule is stable, broad, and well documented.
Code Example
builder.Services.AddControllersWithViews(options =>
{
options.Conventions.Add(
new MyApplicationModelConvention());
});