Skip to content
Learn Netverks

Lesson

Step 13/36 36% through track

program-cs

Program.cs and hosting

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Program.cs and hosting: the syntax, APIs, and habits you need before advancing in ASP.NET.

Teams ship Program.cs and hosting on every ASP.NET codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Program.cs and hosting in contexts like: Line-of-business APIs, intranets, BFF layers, and cloud-hosted services on Linux or Windows.

Write C# (top-level or Program class), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. WebApplication.CreateBuilder loads configuration and logging
  2. Services registered in DI container (AddControllers, AddDbContext)
  3. Middleware pipeline built (Use* then Map*)
  4. Run() starts Kestrel and blocks until shutdown

Important interview questions and answers

  1. Q: Program.cs vs Startup.cs?
    A: .NET 6+ merges both into Program.cs; older tutorials split ConfigureServices/Configure.
  2. Q: What is WebApplication?
    A: Combined host + pipeline builder simplifying bootstrapping.

Self-check

  1. Where do you register services for DI?
  2. What method starts the web server?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • WebApplication builder?
  • Top-level in Program?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump