ASP.NET Core MVC follows the Model-View-Controller architectural pattern, separating application logic into three interconnected components. This promotes separation of concerns, testability, and maintainability.
var builder = WebApplication.CreateBuilder(args);
ASP.NET Core has a built-in IoC (Inversion of Control) container for dependency injection:
// Different service lifetimes demonstrated in your code:
// SCOPED - One instance per HTTP request
builder.Services.AddScoped(typeof(ISpellChecker), typeof(EnglishSpellChecker));
// SINGLETON - One instance for application lifetime
builder.Services.AddSingleton(typeof(ISpellChecker), typeof(EnglishSpellChecker));
// TRANSIENT - New instance every time requested (not shown but available)
builder.Services.AddTransient<ISpellChecker, EnglishSpellChecker>();
builder.Services.AddControllersWithViews();
Registers essential MVC services: