当前位置:网站首页>在 .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
边栏推荐
- VS克隆时显示403错误
- [combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
- Why does thread crash not cause JVM crash
- The calculation of stripe, kernel and padding in CNN
- Mongodb installation & Deployment
- Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
- Bigvision code
- The series of hyperbolic function in daily problem
- 渤、黄海的潮汐特征
- Mongodb replication set [master-slave replication]
猜你喜欢
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
The calculation of stripe, kernel and padding in CNN
Introduction à mongodb
Why does thread crash not cause JVM crash
Recursion: depth first search
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
Tidal characteristics of the Bohai Sea and the Yellow Sea
Table structure of Navicat export database
ffmpeg下载安装教程及介绍
随机推荐
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
Summary of electromagnetic spectrum
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
Limit of one question per day
Captura下载安装及在Captura配置FFmpeg
递归:一维链表和数组
[learning notes] seckill - seckill project - (11) project summary
Ansible introduction [unfinished (semi-finished products)]
Hutool动态添加定时任务
Role of JS No
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
渤、黄海的潮汐特征
UMI route interception (simple and rough)
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
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
Separable bonds and convertible bonds
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
CEPH Shangwen network xUP Nange that releases the power of data
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences