ASP.NET Core MVC Architecture - In-Depth Notes

Overview

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.

1. Program.cs - Application Entry Point

WebApplication Builder Pattern

var builder = WebApplication.CreateBuilder(args);

Service Registration & Dependency Injection

Service Container

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>();

Service Lifetimes Explained

  1. Singleton: Created once, shared across all requests
  2. Scoped: Created once per HTTP request
  3. Transient: Created every time requested

MVC Services Registration

builder.Services.AddControllersWithViews();

Registers essential MVC services: