Modern ASP.NET Core uses a minimal Program.cs entry point—top-level statements configure the host, services, and middleware pipeline. This replaced the older Startup.cs split in many templates.
Minimal hosting model (.NET 6+)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
What happens at startup
WebApplication.CreateBuilderloads configuration and logging- Services registered in DI container (
AddControllers,AddDbContext) - Middleware pipeline built (
Use*thenMap*) Run()starts Kestrel and blocks until shutdown
Important interview questions and answers
- Q: Program.cs vs Startup.cs?
A: .NET 6+ merges both into Program.cs; older tutorials split ConfigureServices/Configure. - Q: What is WebApplication?
A: Combined host + pipeline builder simplifying bootstrapping.
Self-check
- Where do you register services for DI?
- What method starts the web server?