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

边栏推荐
- JS music online playback plug-in vsplayaudio js
- Four logs of MySQL server layer
- BUAA计算器(表达式计算-表达式树实现)
- 多项目编程极简用例
- Blue Bridge Cup - day of week
- Pytorch load data
- Introduction to DeNO
- MySQL reads missing data from a table in a continuous period of time
- Quartz misfire missed and compensated execution
- MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
猜你喜欢
![[practice] mathematics in lottery](/img/29/2ef2b545d92451cf083ee16e09ffb4.jpg)
[practice] mathematics in lottery

1.16 - check code

Do you know cookies, sessions, tokens?

给新人工程师组员的建议

1、工程新建

EDCircles: A real-time circle detector with a false detection control 翻译

KS008基于SSM的新闻发布系统

BUAA喜鹊筑巢
![[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board](/img/07/973722bf484b374f752177dfc48ef5.png)
[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board

简易博客系统
随机推荐
No qualifying bean of type ‘......‘ available
User perceived monitoring experience
Differential GPS RTK thousand search
Indicator system of KQI and KPI
The solution of permission denied (750 permissions should be used with caution)
Factors affecting user perception
Schnuka: 3D vision detection application industry machine vision 3D detection
UDP reliable transport protocol (quic)
Esbuild & SWC: a new generation of construction tools
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
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
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
Prime protocol announces cross chain interconnection applications on moonbeam
[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
11. Container with the most water
施努卡:视觉定位系统 视觉定位系统的工作原理
出现Permission denied的解决办法(750权限谨慎使用)
SAP ALV color code corresponding color (finishing)
Pointer for in-depth analysis (problem solution)
施努卡:什么是视觉定位系统 视觉系统如何定位