The Two Halves of Program.cs in .NET
dev.to·4h·
Discuss: DEV
Flag this post

If you’ve recently jumped into .NET 6 or newer, the first file you see might be Program.cs which looks very different. The old Startup.cs file is gone, and everything is in one, minimal file.

It might look confusing, but this new Program.cs is really just a file split into two distinct jobs.

  1. The “Builder” Phase: Setting up all your tools and services.
  2. The “Pipeline” Phase: Defining the steps to handle a web request.

Let’s break it down.

Part 1: The “Builder” Phase (The Setup)

Every new .NET web app starts with this line:

var builder = WebApplication.CreateBuilder(args);

Builder is like a setup-kit. Before you can do anything, you need to “prepare” the application. This is where you setup all the services, tools, and configurations needed to run your…

Similar Posts

Loading similar posts...