c# - 如何将 Startup.cs 合并到 Program.cs

标签 c# asp.net-core

我是 ASP.NET Core 新手。我正在使用 ASP.NET Core 7。我读到在 ASP.NET Core 7 中他们删除了 Startup.cs。有人可以告诉我如何在此示例中将 Startup.cs 合并到 Program.cs 中。

https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-1-Call-MSGraph

最佳答案

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,可以通过相应命名的属性从 builderapp 访问配置,并使用 app 执行来自 Startup.Configure 的调用。

另请参阅:

关于c# - 如何将 Startup.cs 合并到 Program.cs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76859173/

相关文章:

c# - 在 Angular 6 中传递带有空字符串的整数值时不调用 API Get 方法

c# - 在 ASP.NET MVC 中为用户实现暂停或处罚系统

c# - ASP 下拉列表 selectedvalue 在按下按钮时为空白

c# - 如何添加自定义 header ,然后在兔子消息 header 中检索自定义 header

c# - .NET 核心 : How to use csproj-based projects alongside project. JSON?

asp.net - 跨 MVC 5 和 ASP.NET Core 应用程序的基于 Cookie 的表单例份验证

dependency-injection - 可以从 ASP.NET Core 项目中的 Simple Injector 注入(inject) IAsyncActionFilter 吗?

c# - 使用参数的 Sqlite WHERE 子句

c# - xUnit 不会将消息写入输出 Pane

c# - 事务 Rollback() 是否有机会抛出异常?