ASP. NET MVC5 website development project framework (2), mvc5 Development Project
A few days ago, I started my project and thought a lot about how to do it myself. But after all, I don't know whether these ideas are necessary or not, but Grandpa Deng said, "crossing the river by feeling the stones. During this time, I have read some blogs, especially @ kencery.
I. Basic Framework
Let's talk about the basic framework first. Seven projects are suddenly messy. In my understanding, M is the data carrier among M, V, and C, V is the attempt of the user. C is mainly responsible for coordinating and controlling operations related to the user interface. Data processing and database operations are handed over to DAL and BLL. The entire idea is: View is the interface that the user sees; Controller is responsible for coordinating user operations and looking for the business logic layer when data is needed or processed; when the business logic layer needs to access the database, it finds the data access layer. The data access layer interacts with SQL Server through EF. The data interaction media between layers is Model.
Here, IBLL and IDAL are interfaces and functions are implemented in BLL and DAL. They seem redundant, but they are still very useful. One is that the interface only implements the method definition at a glance; the other is that as long as the interface remains unchanged, no matter how the implemented code is written to the call between projects, it will not change.
2. Project Establishment
1. Create a Web project.
Choose template> Visual C #> Web> ASP. NET Web application.
Here, there is a significant change with vs2012, In a template made by webform, mvc, api, etc.
What if I want to develop it as before? Click web-> Visual Studio 2012.
Choose Web> ASP. NET Web application.
Select MVC here (you can add webform and api references to bring together previous projects. Here, only MVC is selected. for authentication, select an individual user account. This will add the latest ASP. NET Identity usage code (in fact, it doesn't matter what you choose. ASP is not used here. NET Identity. You can choose whether to manage the user or choose to check how Microsoft code is written ).
2. Create 6 Other Projects
Right-click solution> Add> new project
Select project type> Visual C #> Windows> class library.
To create six other projects.
The framework after completion is as follows:
3. References between projects
After a project is created, you must add references between projects.
Right-click a web project reference and choose solution> Add Ninesky. Models, Ninesky. Common, Ninesky. IBLL, and Ninesky. BLL references to the project.
Add Ninesky. Models reference to IDAL in sequence
Add Ninesky. Modles and Ninesky. IDAL references to DAL
Add Ninesky. Modles reference to IBLL
Add Ninesky. Models, Ninesky. IDAL, Ninesky. DAL, and Ninesky. IBLL references to BLL.
In addition, DAL Models must add an EntityFramework reference to Nuget. The method is to right-click the project reference and choose manage NUGET package. In the displayed window, choose online> nuget.org> EntityFramework and click Install to automatically complete the installation.
Now the framework is complete. Here, the web project represents v and c in mvc. The modle project represents m. The common project is ready to write public methods. The other four projects are regarded as the data access layer and business logic layer in the three-tier architecture. In addition, interfaces are used. You can finally write code next time.