Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Net 6 how to develop TodoList application

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to develop TodoList applications in .NET 6". In daily operation, I believe many people have doubts about how to develop TodoList applications in .NET 6. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to develop TodoList applications in .NET 6. Next, please follow the editor to study!

1. Column description

The reason for choosing TodoList is that the project is simple enough, but also enough to cover the knowledge points I want to cover. For readers, there are some pre-requirements for the following suggestions:

Need to be able to write caching, do not need .NET (Core) related development experience.

Need the development experience of the back-end service, have a certain understanding of the basic server-side related characteristics.

Have a basic understanding of Clean Architecture.

two。 Series navigation

2.1 use .NET 6 to develop TodoList application article index

Attached: changes in the code of the .NET 6 Web API project

2.1.1 create a project

Mkdir ProjectName & & cd ProjectNamedotnet new sln-n SampleApidotnet new project-f net6.0-n SampleApi-o SampleApidotnet sln SampleApi.sln add SampleApi/SampleApi.csprojdotnet restoredotnet run-p SampleApi/SampleApi.csproj2.1.2.NET 6 WebAPI Program.cs changes

Var builder = WebApplication.CreateBuilder (args); / / Add services to the container.builder.Services.AddControllers (); builder.Services.AddEndpointsApiExplorer (); builder.Services.AddSwaggerGen (); var app = builder.Build (); / / Configure the HTTP request pipeline.if (app.Environment.IsDevelopment ()) {app.UseSwagger (); app.UseSwaggerUI ();} app.UseHttpsRedirection (); app.UseAuthorization (); app.MapControllers (); app.Run (); 2.1.3Change 1: Top-level statements

The top-level declaration allows us to write the Program class without defining the class, omitting the Main function definition, and writing the method body directly. The compiler automatically adds namespaces and related definitions to us during the compilation phase.

2.1.4Change 2: Implicit using directives

The implicit using instruction is that the compiler automatically generates a file called CompanyEmployees.GlobalUsings.g.cs during the compilation phase according to the type of the project.

The contents are as follows:

/ / global using global::Microsoft.AspNetCore.Builder;global using global::Microsoft.AspNetCore.Hosting;global using global::Microsoft.AspNetCore.Http;global using global::Microsoft.AspNetCore.Routing;global using global::Microsoft.Extensions.Configuration;global using global::Microsoft.Extensions.DependencyInjection;global using global::Microsoft.Extensions.Hosting;global using global::Microsoft.Extensions.Logging;global using global::System;global using global::System.Collections.Generic;global using global::System.IO;global using global::System.Linq Global using global::System.Net.Http;global using global::System.Net.Http.Json;global using global::System.Threading;global using global::System.Threading.Tasks

You can also modify the following properties in the CompanyEmployees.csproj project configuration file to disable the global implicit using directive:

Disable2.1.5Change 3: No Startup class

When it comes to .NET 6, the ConfigureServices and Configure method that has been with us for several versions has finally disappeared, and instead, the configuration of both parts is concentrated in Program.cs. It is not difficult for friends who have written the .NET Core WebAPI to see where to write now.

For some large projects, we certainly can't just write these two parts in Program.cs. Later, we will find a way to separate these two parts and configure them.

Of course, there is no problem with the old version of the project with Startup.cs open under .NET 6.

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.2app.Run and app.Use

App.Run is used to terminate the chained call to Pipeline and return to the client

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

App.Use is used to insert a piece of logic into Pipeline as part of a chained call.

Public static IApplicationBuilder Use (this IApplicationBuilder app, Func middleware); 2.2.3app.Map and app.MapWhen

Both methods are used for branching Pipeline call chain processing in chained calls to middleware.

Public static IApplicationBuilder Map (this IApplicationBuilder app, PathStringpathMatch, Action configuration) public static IApplicationBuilder MapWhen (this IApplicationBuilder app,Func predicate, Action configuration)

App.MapGet 、 app.MapPost 、 app.MapPut 、 app.Delete 、 app.MapMethods

A new feature in .NET 6 is called Minimal APIs, which allows applications to respond to client requests in this form, which is very useful in the process of quickly building micro-service applications. In this series, because you are building a single application, I intend to put this knowledge into the second series of micro-service development practices to see if there is a more appropriate scenario to show.

At this point, the study of "how to develop TodoList applications in .NET 6" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report