当前位置:网站首页>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
边栏推荐
- Schnuka: what is visual positioning system and how to position it
- Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
- Canvas cut blocks game code
- 2.2 STM32 GPIO operation
- Deno介绍
- 简易博客系统
- Esbuild & SWC: a new generation of construction tools
- Cubemx transplantation punctual atom LCD display routine
- Python implementation of maddpg - (1) openai maddpg environment configuration
- JS Vanke banner rotation chart JS special effect
猜你喜欢
Cf464e the classic problem [shortest path, chairman tree]
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
pytorch加载数据
JVM的手术刀式剖析——一文带你窥探JVM的秘密
Svg drag point crop image JS effect
RT thread -- FTP of LwIP (2)
Schnuka: 3D vision detection application industry machine vision 3D detection
2.1 rtthread pin设备详解
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
C#(三十)之C#comboBox ListView treeView
随机推荐
[matlab] - draw a five-star red flag
JS Vanke banner rotation chart JS special effect
Blue style mall website footer code
Flask learning and project practice 9: WTF form verification
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
pytorch加载数据
2.2 STM32 GPIO operation
多项目编程极简用例
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
关于非虚函数的假派生
Blue Bridge Cup - day of week
[optimization model] Monte Carlo method of optimization calculation
[001] [stm32] how to download STM32 original factory data
出现Permission denied的解决办法(750权限谨慎使用)
Suggestions for new engineer team members
Introduction to data types in MySQL
SAP ALV color code corresponding color (finishing)
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
[American competition] mathematical terms
在 .NET 6 中使用 Startup.cs 更简洁的方法