当前位置:网站首页>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
边栏推荐
- Containerization Foundation
- An article will give you a comprehensive understanding of the internal and external components of "computer"
- Codeforces Global Round 19
- Prime protocol announces cross chain interconnection applications on moonbeam
- Mathematical modeling regression analysis relationship between variables
- 2.2 STM32 GPIO operation
- C#(二十七)之C#窗体应用
- User perceived monitoring experience
- 2.1 rtthread pin设备详解
- Pytorch load data
猜你喜欢
How to modify field constraints (type, default, null, etc.) in a table
On Data Mining
阿里测试师用UI自动化测试实现元素定位
cookie,session,Token 这些你都知道吗?
Record the process of reverse task manager
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
KS008基于SSM的新闻发布系统
1. New project
MySQL reads missing data from a table in a continuous period of time
EDCircles: A real-time circle detector with a false detection control 翻译
随机推荐
简易博客系统
mysql关于自增长增长问题
cookie,session,Token 这些你都知道吗?
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
2.2 STM32 GPIO operation
2.2 fonctionnement stm32 GPIO
MySQL 中的数据类型介绍
Multi project programming minimalist use case
[Massey] Massey font format and typesetting requirements
Brush questions in summer -day3
Blue style mall website footer code
Factors affecting user perception
C#(二十七)之C#窗体应用
【Rust 笔记】18-宏
Python implementation of maddpg - (1) openai maddpg environment configuration
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
[practice] mathematics in lottery
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
【Qt5】Qt QWidget立刻出现并消失
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation