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

边栏推荐
- Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
- [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
- Message queue addition failure
- Makefile demo
- C语言HashTable/HashSet库汇总
- Pytorch multi card distributed training distributeddataparallel usage
- Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
- leetcode:动态规划模板
- 动态规划:最长回文子串和子序列
- 监听对象中值变化及访问
猜你喜欢

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

Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet

Download and install node, NPM and yarn

简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息

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

Makefile demo

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

Download and install captura and configure ffmpeg in captura

Mysql Mac版下载安装教程
随机推荐
[MySQL] the difference between left join, right join and join
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Applet get user avatar and nickname
[mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
Web session management security issues
Ansible introduction [unfinished (semi-finished products)]
2020-01-01t00:00:00.000000z date format conversion
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
900w+ data, from 17s to 300ms, how to operate
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Open Visual Studio 2010 hangs when opening a SQL file sql file
403 error displayed when vs cloning
Leetcode: dynamic planning template
Recursion: quick sort, merge sort and heap sort
Don't use the new Dede collection without the updated Dede plug-in
Use three JS make a simple 3D scene
Limit of one question per day
Download and install node, NPM and yarn
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!