当前位置:网站首页>在 .NET 6 项目中使用 Startup.cs
在 .NET 6 项目中使用 Startup.cs
2022-07-03 03:39:00 【dotNET跨平台】

对于 .NET 6 项目,现在已经找不到 Startup.cs 文件。默认情况下,此文件已经被删除,并且 Program.cs 是配置依赖注入服务和 Middleware 的新位置。
但是,有些人可能更喜欢使用 Startup.cs , 并且我也是,可能已经习惯了, 所以在这篇文章中,我会在 .NET 6 项目中添加 Startup.cs。
使用 .NET 6 项目, Program.cs 文件大概会像下面这样, 添加服务和使用中间件都在其中。

现在,我们手动添加一个 Startup.cs 文件,并编写下面的代码

这些代码我们应该都很熟悉了,其中包含了 ConfigureService() 和 Configure() 方法,并添加了一些服务,以及使用了中间件。
接下来,我们还需要修改一下 Program.cs 文件, 使用我们新加的 Startup.cs。

看上去不错!和之前相比,已经变得很简洁了!
当然,您也可以使用其他的方法名,比如把 ConfigureService 换成 RegisterServices, 把
Configure 换成 SetupMiddleware, 如下

现在,熟悉的老朋友 Startup.cs 又回来了!
END

边栏推荐
- C language hashtable/hashset library summary
- Nce detail of softmax approximation
- Recursion: depth first search
- C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode
- NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
- 递归:一维链表和数组
- [MySQL] the difference between left join, right join and join
- MongoDB簡介
- Download and install captura and configure ffmpeg in captura
- CEPH Shangwen network xUP Nange that releases the power of data
猜你喜欢

Nce detail of softmax approximation

Makefile demo

TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network

Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange

Error in compiled file: error: unmapped character encoding GBK

Why does thread crash not cause JVM crash

How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo

IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network

docker安装及启动mysql服务

CEPH Shangwen network xUP Nange that releases the power of data
随机推荐
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
Pytorch轻量级可视化工具wandb(local)
Leetcode: dynamic planning template
[mathematical logic] predicate logic (individual word | individual domain | predicate | full name quantifier | existence quantifier | predicate formula | exercise)
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
leetcode:动态规划模板
Vs 2019 configuration tensorrt
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
Tidal characteristics of the Bohai Sea and the Yellow Sea
redis在服务器linux下的启动的相关命令(安装和配置)
[combinatorics] basic counting principle (addition principle | multiplication principle)
渤、黄海的潮汐特征
navicat 导出数据库的表结构
Mongodb master profile
MongoDB簡介
Nce detail of softmax approximation
Applet (continuous update)
Vs 2019 installation and configuration opencv
Commands related to the startup of redis under Linux server (installation and configuration)