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

边栏推荐
- 1、工程新建
- Prime protocol announces cross chain interconnection applications on moonbeam
- Four logs of MySQL server layer
- P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
- 出现Permission denied的解决办法(750权限谨慎使用)
- 3分钟带你了解微信小程序开发
- Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
- [slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
- JS Vanke banner rotation chart JS special effect
- Do you know cookies, sessions, tokens?
猜你喜欢

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

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

【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板

three. JS page background animation liquid JS special effect

Microkernel structure understanding

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

记录一下逆向任务管理器的过程

SAP ALV color code corresponding color (finishing)

SWC introduction

Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
随机推荐
User perceived monitoring experience
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
A brief introduction to symbols and link libraries in C language
Cubemx 移植正点原子LCD显示例程
数据分析——seaborn可视化(笔记自用)
3.1 rtthread 串口设备(V1)详解
Pytoch foundation - (2) mathematical operation of tensor
有条件地 [JsonIgnore]
Crawler of explanation and application of agency theory
[analysis of variance] single factor analysis and multi factor analysis
2.2 STM32 GPIO操作
1. New project
SAP ALV cell level set color
Edcircles: a real time circle detector with a false detection control translation
RT thread -- FTP of LwIP (2)
施努卡:视觉定位系统 视觉定位系统的工作原理
Factors affecting user perception
KS008基于SSM的新闻发布系统
Basic concepts of LTE user experience
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )