Categories: ASP.NETASP.NET MVC

Building MVC pattern project by Visual Studio 2017 ( ASP.Net framework Part )

Step 14. Edit the unit test project. I only demo the simple unit test method, which focuses on a Get method called the GetData() way of the infra project. Change the unit test project default file name from “unitTest1” to “Enterprise_MVC_WebAppUnitTest” under the Enterprise_MVC_WebApplication.Tests project. The unit test project must add the infra project and the core project to the unit project reference part.

Fig 21. Unit test source code

Step 15. Now, we come back to the MVC web application project to edit. The web application project must install Unity.MVC NuGet package by the NuGet Package Manager platform in Visual Studio. After installing Unity.MVC NuGet package, the web project will add two files, such as UnityConfig.cs and UnityMvcActivator.cs.

Fig 22 Solution Explorer – Enterprise_MVC_WebApplication about Unity.MVC
public static void RegisterTypes(IUnityContainer container)
 {
     container.RegisterType();
 }

Step 16. Create the new controller file which name is Enterprise_MVC_WebApp. Right-Click on the Controller folder -> Add -> Controller (Choose the empty controller file). You can also choose the controller file with the view, using Entity Framework. The model class filed chooses the model class file from the core project. The Data Context field chooses the DB context file from the infra project. If you chose the empty controller files, please follow the below code:

Fig 23 Enterprise_MVC_WebApp controller file source code

Note: If you want to know the complete source code, please click my GitHub link on the profile page. I don’t completely follow the Visual Studio help me to create the CRUD code, so my UI design is simply style. I just proved the simple CRUD code.

Step 17. Copy the database connection string of the infra project to the web project config file.

Fig 24 Web project’s config file.

Conclusion

We have entirely created the MVC pattern of the ASP.Net framework web application, the enterprise level. You can find out the web application project’s bin folder has the dll file of the core project, the dll file of the infra project, and the infra project’s dll config file. The infra project and the core project will package the class library project file to the dll file that doesn’t worry about the other extra factor affect the web application projects. When you want to run a web application under the debug model, you can set break-points in the core project or the infra project, ensuring your source code is correct.

Next part – ASP.NET Core framework part.

Page: 1 2 3 4

davidsky69

View Comments

Recent Posts

Behavioral Patterns – Mediator

Mediator – It can let the program reduces chaotic dependencies between objects. This pattern can restrict the…

5 years ago

Behavioral Patterns – Iterator

Iterator – It let the programs traverse all of the collection elements without their underlying representation and…

5 years ago

Behavioral Patterns – Interpreter

Interpreter –  It provides to evaluate the language grammar and description. This idea bases on having…

5 years ago

Behavioral Patterns – Command

Command – It turns the client’s requests into a stand-alone object which contains all information about the…

5 years ago

Behavioral Patterns – Chain of Responsibility

Chain of Responsibility – It lets the program passes the client requests along a chain of handlers.…

5 years ago

Design Patterns – Behavioral Patterns

The behavioral patterns are about identifying the common communication patterns between objects and bring about…

5 years ago