In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to build an asp.net core project". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Project construction
Put aside the previous project, and now follow me to create a new project, and the first step is still to create a solution:
Dotnet new sln-name Template
Let me first introduce this project (refers to the whole project, not a separate asp.net core application), this is a background management template application, which provides common background system (administrator side) functions, including employee management, department management, role management and other functions.
Now back to the project, usually a project requires a model layer, a data supply layer, and a web presentation layer. Then, we create three projects: Data, Domain, and Web, in which Data and Domain are classlib,Web and mvc projects.
# make sure the current directory is in the same directory as Template.sln
Dotnet new classlib-name Data
Dotnet new classlib-name Domain
Dotnet new mvc-name Web
Add three projects to the solution:
Dotnet sln add Data
Dotnet sln add Domain
Dotnet sln add Web
Because the model layer is stored in Data, other projects need to have a reference to it:
Cd Domain
Dotnet add reference.. / Data
Cd.. / Web
Dotnet add reference.. / Data
Of course, in the actual development, we should also have a Service layer, which is used to store business code and reduce unnecessary business code in the controller. So go on:
# return to the root directory of the project
Cd..
Dotnet new classlib-name Service
Dotnet sln add Service
Then add a reference to Service:
Cd Service
Dotnet add reference.. / Data
Add a reference to Service to Web:
Cd.. / Web
Dotnet add reference.. / Service
Now a large project is basically interface-oriented programming, several key layers should be the interface layer, we actually lack the implementation layer of Domain and the implementation layer of Service.
Cd..
Dotnet new classlib-name Domain.Implements
Dotnet new classlib-name Service.Implements
In the corresponding implementation layer, introduce the interface layer of their implementation, and introduce Data:
Cd Domain.Implements
Dotnet add reference.. / Data
Dotnet add reference.. / Domain
Cd.. / Service.Implements
Dotnet add reference.. / Data
Dotnet add reference.. / Domain
Dotnet add reference.. / Service
Here, a reference to the Domain interface layer is added to the implementation layer of Service, rather than an implementation layer reference. This is because interface-oriented programming requires us to hide the implementation of Domain from the Service implementation layer, so for the implementation layer of Service, we do not need to care about the implementation logic of the Domain layer.
Add references to the two newly created implementation layers in Web:
Cd.. / Web
Dotnet add reference.. / Domain.Implements
Dotnet add reference.. / Service.Implements
Add these two implementation layers to the solution:
Cd..
Dotnet sln add Domain.Implements
Dotnet sln add Service.Implements
The following is the project structure diagram so far:
On the whole, Data is the basis for data flow between layers, so each project depends on this project, and the implementation layer of each interface layer is only visible to Web, while the other layers are actually not clear about the specific implementation.
What are the benefits of hiding the implementation layer?
The caller does not know the logic of the implementer to avoid the caller's dependence on a specific implementation.
It is beneficial to teamwork, some teams are for module division, some are for hierarchical division, either way, using interfaces is a good choice.
Conducive to post-optimization, you can easily switch implementation layers without having to recompile too much code
Of course, there are not only these benefits, but there is a downside: calling the service layer in the web layer will be more cumbersome, but this is not insurmountable, and the following content will show you how to solve this problem.
two。 Project supplement
Typically, a complete project also has a tool project and a test project. So, continue to add the following items:
Dotnet new classlib-name Utils
Utils represents tool classes, and there are usually more tool classes in a project, so it is drawn into a project and listed separately.
Add a test project:
Dotnet new nunit-name Test
The nunit 3 testing framework is used here, and of course there is another xunit testing framework.
Add two projects to the solution:
Dotnet sln add Utils
This is the end of dotnet sln add Test's "how to build the asp.net core Project". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.