ASP.NET development actual combat - (f) ASP.NET MVC & layered code articles

 An article on how to regulate the use of ASP.NET introduced, this chapter will be applied to modify the code according to a blog on the conclusions drawn.

Code stratified

  Considering the blog application code into the following levels:

  ○ Model: data model represents the application, the corresponding database table structure. As well as a data exchange target between the logical layer and the MVC (DTO subsequent use in place).
  ○ Storage: used to manage data add, delete, search, change.
  ○ logic: the business logic for processing, is generally performed according to the data to drive the business layer provides the application business logic will be used to persist the data storage.
  ○ Application: that is MVC application that provides user interface (UI) for the user, and then call the business logic to complete.

 

Create a class library project as a model, warehousing and logic

  1. Use VS2017 to create three class library projects, namely BlogBusinessLogic, BlogModel, BlogRepository:

  

  Dependencies between them is as follows:

  

  2. My Blog transferred to the Post class in BlogModel (copy when it should be noted namespace):

   

  

  3. Create a Blog warehousing (here still use a static list to represent a data source):

  

    

  4. Create BlogManager as a simple business logic manager:

   

  5. In view model MVC is defined for displaying:

  Article Details Model:

   

  Article list model:

  

  6. BlogManager the Controller:

  

  

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

  

  

  8. operating results, before and still the same:

  

  

summary

  This chapter is only the original MVC application has been split according to an analysis of the purpose of the split is to separate concerns, ease of management and maintenance of the code. Note that split from the code can be seen in the method call storage layer logical layer calls from MVC get a list of articles, information and logic layer method are basically the same, and no additional logic is added, because the current business logic relatively simple, but not useless.

 

Welcome to add a personal Micro Signal: Like if thoughts.

I welcome the attention of the public numbers, not only recommend the latest blog for you, there are more surprises waiting for you and resources! Learn together and common progress!

 

Guess you like

Origin www.cnblogs.com/cool2feel/p/11544490.html