This chapter will modify the blog application code based on the conclusions of the previous article, which introduced how to use ASP.NET in a standardized manner.

Layer code

Overall consideration, blog application code is divided into the following levels:

○ Model: Represents the data model in the application and corresponds to the database table structure. It also acts as a data exchange object between MVC and logical layer (dtos will be used instead later). ○ Storage: used to manage data addition, deletion, search and change. ○ Logic: Used to process business logic. Generally speaking, business logic drives business execution based on data provided by the application layer. Business logic uses warehousing to persist data. ○ Application: An MVC application provides users with an operation interface (UI) and invokes logic to complete services.

 

Create class library projects for models, repositories, and logic

BlogBusinessLogic; BlogModel; BlogRepository; BlogBusinessLogic;

  

Their dependencies are as follows:

  

2. Move the Post class from My Blog to BlogModel (note the namespace when copying) :

   

  

3. Create the Blog repository (still using static lists to represent a data source) :

  

    

4. Create BlogManager as a simple business logic manager:

   

5. Define the view model in MVC to display:

Detailed model:

   

Article list model:

  

6. Use BlogManager in Controller:

  

  

7. Modify the page and use Model to render the page:

  

  

8. The running result is still the same as before:

  

  

summary

This chapter just splits the original MVC application based on the previous analysis. The purpose of splitting is to separate concerns and facilitate code management and maintenance. It should be noted from the split code that the method of getting the list of articles and information from the MVC call logic layer is basically the same as the method of the logic layer calling the repository layer. No additional logic is added, because the business logic is relatively simple now, rather than useless.

   

This paper addresses: www.cnblogs.com/selimsong/p…

ASP.NET has no magic — directories