我是 ASP.NET Core 新手。我正在使用 ASP.NET Core 7。我读到在 ASP.NET Core 7 中他们删除了 Startup.cs
。有人可以告诉我如何在此示例中将 Startup.cs
合并到 Program.cs
中。
最佳答案
I read that in ASP.NET Core 7 they got rid of Startup.cs.
不完全是。 ASP.NET Core 6 引入了一种新的所谓的最小托管模型(默认模板使用该模型)。但您可以自由保留the generic hosting model如果你愿意的话。
How to merge Startup.cs into Program.cs
简而言之 - 将 ConfigureServices
中的所有内容移至 var app = builder.Build();
调用之前,并将 Configure
中的所有内容移至其之后(查看默认模板生成的代码)。要设置服务,您可以使用 builder.Services
,可以通过相应命名的属性从 builder
和 app
访问配置,并使用 app
执行来自 Startup.Configure
的调用。
另请参阅:
关于c# - 如何将 Startup.cs 合并到 Program.cs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76859173/