SoFunction
Updated on 2025-03-09

.NET 6 Development of TodoList Application Implementation Series Background

Preface:

When I thought of writing such a series of blogs, I had two original intentions: one is to connect the basic knowledge of .NET 6 WebAPI development through a practical project to help those who want to get started with .NET 6 server development quickly, have a basic understanding and mastery of the technology of using .NET 6 to develop back-end services, and check my own skill tree by the way; the other is to hope to provide some small help to the domestic .NET environment. At first, I was born in C# desktop application, but with the prosperity of the Internet industry and Microsoft's stubbornness in the early years, the domestic .NET development environment has shrunk to several fixed fields, so many people still believe that C# and .NET are not suitable for large-scale enterprise-level applications today, and this concept needs to be changed. I have no intention of comparing the quality of technology and language, but I prefer to see that the domestic technology environment can also show a state of controversy among hundreds of schools of thought. After so many years of changes and progress by Microsoft, .NET 6 is a very excellent framework, which I first came into contact with.NET Core 2Since I have evolved year by year, I have deeply felt that I will take out the good things and share them with you.

1. Column Description

In this blog series, I will use .NET 6 to develop one step by step from scratchTodoListIn this process, as many knowledge points as possible are independent into each article, and finally the application is passedDockerPackage and useGithubofActionandAzure Container InstanceServices implement CI/CD.

The reason for choosing TodoList is that this project is simple enough, but it is also enough to cover the knowledge points I want to cover. For readers,There are some recommended prerequisites:

  • You need to know how to write C#, but you don't need it.NET (Core)Related development experience.
  • It requires experience in back-end services and has a certain understanding of basic server-side related features.
  • There is rightClean ArchitectureBasic understanding of .

2. Series navigation

2.1 Develop TodoList application article index using .NET 6

Attachment: Changes in the code of .NET 6 Web API project

2.1.1 Create a project

mkdir ProjectName && cd ProjectName
dotnet new sln -n SampleApi
dotnet new project -f net6.0 -n SampleApi -o SampleApi
dotnet sln  add SampleApi/
dotnet restore
dotnet run -p SampleApi/

2.1. 6 WebAPI changes

var builder = (args);

// Add services to the container.
();
();
();

var app = ();
// Configure the HTTP request pipeline.
if (())
{
    ();
    ();
}

();
();
();
();

2.1.3Change 1: Top-level statements

Top declarations make us writeProgramYou can no longer define the class when you are in the class, omit the Main function definition, and start writing the method body directly. The compiler will automatically add namespaces and related definitions to us during the compilation stage.

2.1.4Change 2: Implicit using directives

ImplicitusingThe directive is that the compiler automatically generates a name called "A" during the compilation stage according to the project type.the file,

The content is as follows:

// <auto-generated/>
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::System;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;
global using global::;


Can also be inModify the following properties in the project configuration file to disable global implicitnessusingThis feature of instruction:

<!-- <ImplicitUsings>enable</ImplicitUsings> -->
<ImplicitUsings>disable</ImplicitUsings>


2.1.5Change 3: No Startup class

When we arrived in .NET 6, we have accompanied us several versions to this dayConfigureServices and ConfigureThe method finally disappeared, instead, the configuration of both parts is concentrated onmiddle. Have written it once.NET Core WebAPIIt is not difficult for me to see where I should write it now.

For some large-scale projects, we can't just write these two parts inInside, we will find a way to separate these two parts and configure them separately.

Of course, the old version containsThe project opens under .NET 6 without any problems.

2.2 Some knowledge points about Pipeline

2.2.1Pipeline Sequence

  • ExceptionHandler
  • HSTS
  • HttpsRedirection
  • Static Files
  • Routing
  • CORS
  • Authentication
  • Authorization
  • Custom Middlewares
  • Endpoint Configuration

2.2. and

Used to terminatePipelinechained call and return to the client

public static void Run(this IApplicationBuilder app, RequestDelegate handler);
public delegate Task RequestDelegate(HttpContext context);


Used toPipelineInsert a piece of logic as one of the links of chain calls

public static IApplicationBuilder Use(this IApplicationBuilder app, Func<HttpContext,
Func<Task>, Task> middleware);


2.2. and

Both methods are used inmiddlewarebranching in chained callsPipelineCall chain processing.

public static IApplicationBuilder Map(this IApplicationBuilder app, PathString
pathMatch, Action<IApplicationBuilder> configuration)
  
public static IApplicationBuilder MapWhen(this IApplicationBuilder app,
Func<HttpContext, bool> predicate, Action<IApplicationBuilder> configuration)


、、、、

A new feature in .NET 6 is calledMinimal APIs, allowing applications to respond to client requests in this form, is very useful in the process of quickly building microservice applications. In this series, because it is a single application, I plan to put this part of the knowledge points into the second series about microservice development practice to see if there are more suitable scenarios to display.

This is the article about the background of the .NET 6 development TodoList application implementation series. For more information about the background of the NET 6 development TodoList implementation series, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!