当前位置:网站首页>在 .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
边栏推荐
- 用Three.js做一個簡單的3D場景
- Leetcode: dynamic planning template
- C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode
- Use three JS make a simple 3D scene
- Table structure of Navicat export database
- MongoDB主配置文件
- Limit of one question per day
- Mongodb replication set [master-slave replication]
- 动态规划:最长公共子串和最长公共子序列
- The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
猜你喜欢
Ansible简介【暂未完成(半成品)】
Introduction à mongodb
docker安装及启动mysql服务
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
js中#号的作用
node,npm以及yarn下载安装
Download and install node, NPM and yarn
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
编译文件时报错:错误: 编码GBK的不可映射字符
随机推荐
Use of sigaction
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
[combinatorics] basic counting principle (addition principle | multiplication principle)
Stepping on pits and solutions when using inputfilter to limit EditText
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
[learning notes] seckill - seckill project - (11) project summary
Web session management security issues
IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network
VS克隆时显示403错误
Pat class B "1104 forever" DFS optimization idea
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
Hutool动态添加定时任务
Web会话管理安全问题
shardingsphere动态数据源
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
[mathematical logic] normal form (conjunctive normal form | disjunctive normal form | major item | minor item | maximal item | minor item | principal conjunctive normal form | principal disjunctive no
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
Convert binary stream to byte array
递归:一维链表和数组