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

边栏推荐
- [practical exercise] face location model based on skin color
- Flask learning and project practice 9: WTF form verification
- Prime protocol announces cross chain interconnection applications on moonbeam
- Pointer written test questions ~ approaching Dachang
- Blue Bridge Cup - day of week
- [matlab] - draw a five-star red flag
- Cubemx 移植正点原子LCD显示例程
- The solution of permission denied (750 permissions should be used with caution)
- 施努卡:视觉定位系统 视觉定位系统的工作原理
- 关于非虚函数的假派生
猜你喜欢

After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling

Four logs of MySQL server layer

Overview of super-resolution reconstruction of remote sensing images

SWC介绍
![[Massey] Massey font format and typesetting requirements](/img/27/6b641551d6d8699683972f40f3b8e5.jpg)
[Massey] Massey font format and typesetting requirements
![[001] [stm32] how to download STM32 original factory data](/img/5a/02d87fe1409a9427180ecefb8326c6.jpg)
[001] [stm32] how to download STM32 original factory data

Blue Bridge Cup - Castle formula

Brush questions in summer -day3

Image super-resolution using deep convolutional networks(SRCNN)解读与实现

登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
随机推荐
2. GPIO related operations
RT-Thread--Lwip之FTP(2)
C#(三十)之C#comboBox ListView treeView
Containerization Foundation
Prime protocol announces cross chain interconnection applications on moonbeam
C#(二十八)之C#鼠标事件、键盘事件
3.2 detailed explanation of rtthread serial port device (V2)
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
[risc-v] external interrupt
Force buckle 1189 Maximum number of "balloons"
1、工程新建
Failure causes and optimization methods of LTE CSFB
施努卡:什么是视觉定位系统 视觉系统如何定位
cookie,session,Token 这些你都知道吗?
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
Pelosi: Congress will soon have legislation against members' stock speculation
Pytoch foundation - (1) initialization of tensors
Restful style
Esbuild & SWC: a new generation of construction tools
Differential GPS RTK thousand search