当前位置:网站首页>在 .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

边栏推荐
- MongoDB簡介
- Ffmpeg download and installation tutorial and introduction
- Limit of one question per day
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- 没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
- Error in compiled file: error: unmapped character encoding GBK
- Separable bonds and convertible bonds
- softmax的近似之NCE详解
- Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
- numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
猜你喜欢

User value is the last word in the competition of mobile phone market

Message queue addition failure

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check

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

Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information

编译文件时报错:错误: 编码GBK的不可映射字符

Limit of one question per day
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

Web session management security issues

释放数据力量的Ceph-尚文网络xUP楠哥
随机推荐
FileZilla client download and installation
Web会话管理安全问题
Ffmpeg recording screen and screenshot
VS克隆时显示403错误
编译文件时报错:错误: 编码GBK的不可映射字符
CEPH Shangwen network xUP Nange that releases the power of data
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
二进制流转换成字节数组
MongoDB简介
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
MongoDB复制集【主从复制】
Limit of one question per day
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
[mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
Ffmpeg download and installation tutorial and introduction
Error in compiled file: error: unmapped character encoding GBK
Dynamic programming: longest common substring and longest common subsequence
简易版 微信小程序开发之for指令、上传图片及展示效果优化
Tidal characteristics of the Bohai Sea and the Yellow Sea