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

边栏推荐
- ESBuild & SWC浅谈: 新一代构建工具
- [optimization model] Monte Carlo method of optimization calculation
- Do you know cookies, sessions, tokens?
- 有条件地 [JsonIgnore]
- Crawler of explanation and application of agency theory
- 自动化测试怎么规范部署?
- Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
- 简述C语言中的符号和链接库
- Cubemx 移植正点原子LCD显示例程
- 11. Container with the most water
猜你喜欢

C#(三十)之C#comboBox ListView treeView

Flask learning and project practice 8: introduction and use of cookies and sessions
![[practice] mathematics in lottery](/img/29/2ef2b545d92451cf083ee16e09ffb4.jpg)
[practice] mathematics in lottery

1.16 - check code

MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置

C#(三十一)之自定义事件

Alibaba testers use UI automated testing to achieve element positioning

UDP reliable transport protocol (quic)

Schnuka: visual positioning system working principle of visual positioning system

记录一下逆向任务管理器的过程
随机推荐
2.2 STM32 GPIO操作
Recommended papers on remote sensing image super-resolution
2.13 weekly report
JS music online playback plug-in vsplayaudio js
Microkernel structure understanding
3.1 detailed explanation of rtthread serial port device (V1)
Force buckle 1189 Maximum number of "balloons"
Pointer for in-depth analysis (problem solution)
暑期刷题-Day3
Introduction to data types in MySQL
SAP ALV color code corresponding color (finishing)
Multi project programming minimalist use case
Exchange bottles (graph theory + thinking)
[practice] mathematics in lottery
【Rust 笔记】18-宏
阿里测试师用UI自动化测试实现元素定位
[Massey] Massey font format and typesetting requirements
施努卡:3d视觉检测应用行业 机器视觉3d检测
SAP ALV cell level set color
2.2 fonctionnement stm32 GPIO