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

How to develop TodoList applications with. Net 6

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how to develop TodoList applications in .NET 6, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Brief introduction of 1.TodoList requirements

First of all, let's make it clear what the TodoList application we are about to develop needs to accomplish. I won't write down all the features at once, such as allowing users to log in, just list the most basic functional requirements:

We can maintain a TodoList.

TodoList can contain multiple TodoItem.

For TodoList, we can set its name

For each TodoItem, we can set its content, expiration time, and whether it is completed or not.

For all entities, you can complete the operation of adding, deleting, changing and checking.

two。 Development tools

2.1.NET 6

There is nothing to say about .NET 6, just download and install it according to the official instructions.

2.2Visual Studio Code

The reason for using Visual Studio Code is that it is free, cross-platform and functional enough. Although it is not as powerful as Visual Studio, Visual Studio for Mac or Rider in intelligent completion, because you may use different systems and different tools to read this article, I decided to use IDE, which is free for all platforms and consistent in performance, so you can choose one of your own IDE to develop.

Of course, in order to successfully use VScode to develop .NET 6 Web API projects, there are some extension applications that must be installed. Search and install the following extension ID in VSCode's Extension:

Ms-dotnettools.csharp-A required option for VSCode development and debugging C # projects provided by OmniSharp.

Ms-azuretools.vscode-docker-Docker extension.

2.3Hoppscotch

You may not be familiar with the name of this tool, which is used for local testing of Web API projects. You are more familiar with Postman, and the predecessor of this tool is Postwoman, which is now renamed Hoppscotch. After opening Hoppscotch using a browser with Chrome kernel, you can click the available extension flag on the address bar and choose to install it locally for future use:

The interface looks like this when you open it:

The function is very powerful, testing Restful interface, GraphQL interface, real-time communication interface (WebSocket/SSE/Socket.IO/MQTT) can, and the resource consumption is much lower than Postman, good-looking and free. It's a conscience.

Introduction to 3.Clean Architecture

Clean Architecture is an article published by Robert C. Martin on his blog about how to organize application structures and dependencies to achieve a better independent, decoupled multi-tier project structure. It is recommended that you have time to take a good look at this article.

After a long period of practice and evolution, I personally feel that the most concise and comfortable Clean Architecture structure is as follows:

4. Build the solution structure

# create solution directory mkdir TodoList & & cd TodoList# create solution dotnet new sln-n TodoList# according to the project structure of clean architecture Create the WebApi project and the classlib project dotnet new webapi-f net6.0-n TodoList.Api-o. / src/TodoList.Apidotnet new classlib-f net6.0-n TodoList.Application-o. / src/TodoList.Applicationdotnet new classlib-f net6.0-n TodoList.Domain-o. / src/TodoList.Domaindotnet new classlib-f net6.0-n TodoList.Infrastructure-o. / src/TodoList.Infrastructure# according to the structure and dependencies of clean architecture Set references between projects # Application depends only on Domaindotnet add src/TodoList.Application/TodoList.Application.csproj reference src/TodoList.Domain/TodoList.Domain.csproj# Infrastructure, only on Applicationdotnet add src/TodoList.Infrastructure/TodoList.Infrastructure.csproj reference src/TodoList.Application/TodoList.Application.csproj# Api depends on Application and Infrastructuredotnet add src/TodoList.Api/TodoList.Api.csproj reference src/TodoList.Application/TodoList.Application.csprojdotnet add src/TodoList.Api/TodoList.Api.csproj reference src/TodoList.Infrastructure / TodoList.Infrastructure.csproj# adds all items to the sln dotnet sln TodoList.sln add src/TodoList.Api/TodoList.Api.csprojdotnet sln TodoList.sln add src/TodoList.Application/TodoList.Application.csprojdotnet sln TodoList.sln add src/TodoList.Domain/TodoList.Domain.csprojdotnet sln TodoList.sln add src/TodoList.Infrastructure/TodoList.Infrastructure.csproj5. Running

Run when the terminal is located to the current solution directory:

$dotnet restore Determining projects to restore... Restored / Users/yu.li1/Projects/asinta/blogs/cnblogs/TodoList/src/TodoList.Application/TodoList.Application.csproj (in 206ms). Restored / Users/yu.li1/Projects/asinta/blogs/cnblogs/TodoList/src/TodoList.Infrastructure/TodoList.Infrastructure.csproj (in 206ms). Restored / Users/yu.li1/Projects/asinta/blogs/cnblogs/TodoList/src/TodoList.Api/TodoList.Api.csproj (in 306 ms). 1 of 4 projects are up-to-date for restore.$ dotnet run-project src/TodoList.Api/TodoList.Api.csproj Building...info: Microsoft.Hosting.Lifetime [14] Now listening on: https://localhost:7039info: Microsoft.Hosting.Lifetime [14] Now listening on: http://localhost:5050info: Microsoft.Hosting.Lifetime [0] Application started. Press Ctrl+C to shut down.info: Microsoft.Hosting.Lifetime [0] Hosting environment: Developmentinfo: Microsoft.Hosting.Lifetime [0] Content root path: / Users/yu.li1/Projects/asinta/blogs/cnblogs/TodoList/src/TodoList.Api/

Use Hoppscotch to check whether the project runs successfully using the WeatherForecast interface that comes with the WebAPI project:

This is where the project structure is built, and we can delete the files related to the sample WeatherForecast in the Api project and the Class1.cs files in the three class library projects. The final project structure looks like this:

These are all the contents of the article "how to develop TodoList applications in .NET 6". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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