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

边栏推荐
- npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
- Hutool动态添加定时任务
- Change and access of median value of listening object
- IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
- For instruction, uploading pictures and display effect optimization of simple wechat applet development
- 二进制流转换成字节数组
- MongoDB复制集【主从复制】
- ffmpeg下载安装教程及介绍
- node,npm以及yarn下载安装
- Pat class B "1104 forever" DFS optimization idea
猜你喜欢

Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

Summary of electromagnetic spectrum

Ansible简介【暂未完成(半成品)】

ffmpeg下载安装教程及介绍

Makefile demo

IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥

用Three.js做一個簡單的3D場景
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

docker安装及启动mysql服务
随机推荐
Recursion: depth first search
Ffmpeg one / more pictures synthetic video
Yolov5 project based on QT
[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 |
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
Tidal characteristics of the Bohai Sea and the Yellow Sea
redis在服务器linux下的启动的相关命令(安装和配置)
UMI route interception (simple and rough)
错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数
Téléchargement et installation du client Filezilla
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
Recursive use and multi-dimensional array object to one-dimensional array object
小程序获取用户头像和昵称
FileZilla client download and installation
Don't use the new Dede collection without the updated Dede plug-in
Docker install and start MySQL service
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
Hutool dynamically adds scheduled tasks
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line