当前位置:网站首页>In Net 6 CS more concise method
In Net 6 CS more concise method
2022-07-06 03:47:00 【Dotnet cross platform】
If you are following .NET 6, So you should know , stay .NET 6 In the project , No, Startup.cs file , Now we use Program.cs File to complete the unified configuration .
I previously posted an article using .NET 6 Project use Startup.cs The article .
stay .NET 6 Project use Startup.cs
Can it be further improved , Make it better ? Certainly. , Next , I'll show you a more concise approach .
To make the code look simpler , I used the extension method . stay .NET 6 in , Use WebApplicationBuilder Build the program . therefore , We are WebApplicationBuilder and WebApplication Create an extension method .
First , Create a static class RegisterServiceExtensions, Then define RegisterServices Static methods . And then put Program.cs The code of the registration service is migrated here , as follows

Next , We create another static class RegisterMiddlewareExtensions, Then define static methods RegisterServices, And put Program.cs The code of the registered middleware is migrated here .

Last , Update the Program.cs Use these extension methods .

perhaps , Use one line of code directly to complete these tasks .

Now? , Code looks simpler 、 Can be read , And easy to manage .
END
边栏推荐
- Multi project programming minimalist use case
- 11. Container with the most water
- Serial port-rs232-rs485-ttl
- 多项目编程极简用例
- 阿里测试师用UI自动化测试实现元素定位
- 数据分析——seaborn可视化(笔记自用)
- UDP reliable transport protocol (quic)
- 3.2 rtthread 串口设备(V2)详解
- Oracle ORA error message
- three. JS page background animation liquid JS special effect
猜你喜欢
阿里测试师用UI自动化测试实现元素定位
Exness foreign exchange: the governor of the Bank of Canada said that the interest rate hike would be more moderate, and the United States and Canada fell slightly to maintain range volatility
Flask learning and project practice 9: WTF form verification
C language circular statement
Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
MySQL reads missing data from a table in a continuous period of time
遥感图像超分辨重建综述
给新人工程师组员的建议
3.1 detailed explanation of rtthread serial port device (V1)
随机推荐
EDCircles: A real-time circle detector with a false detection control 翻译
Svg drag point crop image JS effect
2.1 rtthread pin device details
【SLAM】ORB-SLAM3解析——跟踪Track()(3)
施努卡:视觉定位系统 视觉定位系统的工作原理
cookie,session,Token 这些你都知道吗?
Pytoch foundation - (2) mathematical operation of tensor
Containerization Foundation
Indicator system of KQI and KPI
User experience index system
[optimization model] Monte Carlo method of optimization calculation
Pytorch基础——(2)张量(tensor)的数学运算
Blue Bridge Cup - day of week
Quick sort function in C language -- qsort
Pytorch基础——(1)张量(tensor)的初始化
Basic concepts of LTE user experience
SWC介绍
Pointer written test questions ~ approaching Dachang
记录一下逆向任务管理器的过程
C#(三十一)之自定义事件