Using MVC5 + EF6 + WebApi as a small feature (4) Project layering and folder naming, mvc5ef6
In the previous section, we completed the construction of a project. We saw a layered architecture of a project. What should we do next and what content should we reference? In this section, we will gradually split the features of each layer by adding a package
Trump. Domain
At this layer, we mainly define the Domain model. As we mentioned earlier, Domain does not depend on any layer. The only possible dependency is the external help class library. Therefore, this layer does not require us to process the reference relationship separately.
At this layer, we mainly define some actions of entities and entities. To make the solution tree look fresh, we add several folders to save the corresponding content.
- Entiies: stores object classes.
- IRepository)
- T4: used to save T4 files. T4 will be used to generate object classes later.
This is enough. If you need to add it separately, you can add the T4 folder without adding it.
Trump. EF
At this layer, we will use the combination of Entity Framework 6 + SQL Server for data persistence. At the same time, we need to implement the warehousing interface defined at the Domain layer, in addition, at this layer, we will use Migration for data Migration and Fluent Api for Data Relationship configuration. Therefore, the files at this layer are as follows:
- Common: Put the public classes we will use, such as the extracted public storage classes.
- EntityConfig: involves the association relationship configuration of object classes. We use Fluent Api to define the relationship between objects.
- Migrations: automatically generated files after data migration is enabled, without manual Creation
- Repository: Warehousing implementation class
- XXXDbContext. cs: Since EF is used for data operations, there must be a data context class. If our project is small, we will not create a folder for it.
These folders are basically used. Let's look at the class libraries we may use in EF,
- Entity Framework: You certainly don't need to think about this. The performance of the ORM that Microsoft has given me over the years should not be a big problem (I guess I haven't tested it, so don't take it ).
This is enough. Other things are not necessary. We can add them when using them. Note that the EntityFramework of the nuget installation package has a corresponding EntityFramework. zh-Hans. install them together, so that you can see the inherited Chinese prompt during code writing.
Finally, at the EF layer, we inherit the warehouse interface of Domain and reference the entity class of Domain. Therefore, we need to rely on the Domain project. Right-click to add a project reference.
Trump. Application
At this layer, we want to isolate the association between the UI Layer and the EF layer. The data Model flow is as follows: Entity → Dto → Model. The conversion of Entity → Dto is completed at this layer. At the same time, we will complete the Assembly of some models that are not completed in the page model here. This layer of folders is as follows:
- Common: public classes, some base classes, and interfaces
- Dtos: Data Transmission object, which converts Entity to Dto and then throws it to the UI Layer.
- IService
- Service: Application Layer implementation.
In fact, if you rely on three layers, the application layer is a bit similar to the original BLL layer, doing some technical work, however, we have to come up with an interface and an implementation method here. This is not for the sake of height. We will use it later when talking about Ioc, at the same time, we have introduced T4 in the Domain. A lot of code in this section can be generated, so there is no need to tangle.
Take a look at the Nuget package to be referenced:
- AutoMapper:Data conversion depends on it. It is said that the performance is not good, but there is no good alternative.
- Newtonsoft. Json: serialized in Json format, which is used in some cases.
Trump. ExamApp
Finally, I came to the UI Layer, where all the things that the user saw were concentrated. At this layer, you need to call the Application to obtain data for display, send the user-submitted forms to the Application, and then send them to the EF layer for persistence.
This layer of folders is basically complete during project creation. Let's take a look at the references of this layer and sort out the technologies we will use.
- AutoMapper: Helps with Dto → Model conversion
- Newtonsoft. Json: used for Json serialization
- Swagger. Net, Swagger. Net. UI, Swashbuckle, and Swashbuckle. Core: used for online Api documentation.
- Log4net: The old log component. It is easy to configure and use according to the instruction manual.
- Bootstrap: current version 3. xxx ~~~~~~
- JQuery: note that there are three series: 1.xx, 2.xx, and 3.xx. Different versions are selected based on client compatibility requirements, which affects the selection of plug-ins during page processing. Exercise caution, the version was accidentally upgraded, resulting in various client incompatibility.
- Datatables: List component
- JsTree: Tree Structure
- Select2: the drop-down list that can be searched and filtered
- Sweetalert2: substitution of browser alert messages
- Jsrender: bind duplicate data on the page in some cases
- Ueditor: Rich Text Editor, which is produced by Baidu. It seems that it is not maintained, it is basically stable, and its functions can be satisfied. The most important thing is to have Chinese documents and examples.
- Icheck and bootstrap-touchspin: Small page function optimization to enhance user experience
The project structure is as follows:
All preparations are complete. The next step begins.
My personal habit is to draw a prototype when organizing the requirements and then design a data model, which is basically the development idea of page design, model design, logic processing, function connection, and test fine-tuning.
However, this is because it was proposed from the project, the requirements have been completed, and a lot of code has been completed, and I don't know where to start.
Sorting out ideas continues, and the first time I want to write a practical article, I find it hard to find out ~