Answer accepted by question author
Hi @Soumyadip Majumder ,
Thanks for reaching out.
For a new ASP.NET Core project in .NET 8 or later, I would generally lean toward following the current template style and using Program.cs with the minimal hosting model. That is the direction the platform has taken since .NET 6, and for many new apps it tends to keep the startup flow simpler and easier to follow.
That said, using Program.cs does not mean everything has to live in one big file. In practice, it often works well to keep Program.cs as the composition root and move the detailed setup into extension methods or separate modules as the app grows. That usually gives you the benefits of the modern hosting model without necessarily ending up with a very large startup file.
For an existing project that already uses Startup.cs, I do not think there is usually a strong need to rewrite it just for the sake of matching the new style. Microsoftβs migration guidance is fairly clear that apps moving to .NET 6 or later do not have to adopt the minimal hosting model right away, and the older Startup pattern is still supported. If the current structure is clean, understandable, and working well, keeping it is often perfectly reasonable.
So for migrated projects, I would usually only consolidate into Program.cs if there is a real payoff, such as simplifying the startup path, aligning the project with current templates, or making onboarding easier for the team. Otherwise, a low-risk migration is often the better engineering choice than a structural rewrite that does not really change behavior.
If you want a middle ground, you can move to the modern hosting model and still keep a Startup-style class for a while by calling it explicitly from Program.cs, for example:
var builder = WebApplication.CreateBuilder(args);
var startup = new Startup(builder.Configuration);
startup.ConfigureServices(builder.Services);
var app = builder.Build();
startup.Configure(app, app.Environment);
app.Run();
The sample above is only for reference, so you may need to adjust it based on your application structure, dependency injection setup, middleware order, endpoint mapping, and any third-party containers or hosting customizations you use.
From a maintainability and team perspective, I would focus less on whether the file is named Startup.cs or Program.cs, and more on whether the startup path is easy to read and change safely. A small or medium app can often be perfectly fine with a single Program.cs. A larger app will usually benefit from extracting service registration and middleware setup into well-named extension methods or feature-level modules instead of letting Program.cs grow too much.
Hope this helps! If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.
-
Soumyadip Majumder 245 Reputation points
@Jack Dang (WICLOUD CORPORATION)
For practice purposes we can keep everything inprogram.csfile. But in real-time projects that contains multiple variants services, middleware; Should I practice withprogram.csandstartup.csboth the files? In .NET 8/10 we can keepstartup.csfile that is optional. -
Jack Dang (WICLOUD CORPORATION) 18,970 Reputation points β’ Microsoft External Staff β’ Moderator
Hi @Soumyadip Majumder ,
I would focus on
Program.cs, because that is the current default approach in .NET 8 and later.At the same time, it is still useful to understand
Startup.cs, since many existing real-world projects still use that pattern. So my suggestion would be: practice building new applications withProgram.cs, and learnStartup.cswell enough to read, maintain, or migrate older codebases when needed. -
Soumyadip Majumder 245 Reputation points
I feel same, some legacy projects or the projects have not only multiple but also variants service configurations and middlewares, we can use
startup.csto seperate the lengthy blocks of code and keep theprogram.csminimal. For new fresh scratch project, we should maintain onlyprogram.csby default but based on business understanding we can usestartup cs, that is optional. -
Jack Dang (WICLOUD CORPORATION) 18,970 Reputation points β’ Microsoft External Staff β’ Moderator
Hi @Soumyadip Majumder ,
Thanks for your feedback.
If my explanation was helpful to you so far, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well. Thank you.
Sign in to comment
