Skip to content

The goal of this project was to create an MVC project on Visual Studio to run a simple CRUD web application using a multitier architecture

Notifications You must be signed in to change notification settings

rembertmagri/web_csharp

Repository files navigation

C# ASP.NET MVC - Proof of Concept project

Purpose

To create a solution on Visual Studio to run a simple CRUD web application using:

Solution Structure and Layer Division

After creating the projects and setting their dependencies,

the database and table were created and some rows were inserted.

Then, the Entity Framework model was created:

Connection string for the creation of the Entity Framework model (database first):

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

Useful references:

Pure MVC project

For the pure MVC part of the project, the native components of MVC were heavily used, such as Html templates (Razor), views, partial views, layouts, navigation ruled by the controllers, etc. No specific javascript library was used.

List+CRUD

Useful references:

MVC + jQuery + Datatables

For the "MVC + jQuery + Datatables" part of the project, the main javascript library used were jQuery, Datatables and jQueryUI (for the modals). In this case, the main visual part of the 'logic' is concentrated in the script POC_Presentation_MVC\Areas\jQueryDatatables\Scripts\Product\DataTable.js.

List+CRUD

Useful references:

MVC + AngularJS

For the "MVC + AngularJS" part of the project, the main javascript library used was AngularJS. In this case, the main visual part of the 'logic' is concentrated in the scripts folder POC_Presentation_MVC\Areas\AngularJS\Scripts\app.

List+CRUD

Useful references:

WebAPI + MVC + jQuery + DataTables

For the WebAPI part of the project, a new area was created in the Presentation project. The datatables javascript from the 'MVC + jQuery and DataTables' project was altered to call the CRUD methods from the WebAPI project. The WebAPI project was created using .Net Core library.

Useful references:

Dependency Injection

To allow the execution of unit tests on each layer, the Unity library was added to the MVC project. Dependency injection (aka Inversion of Control) allows the presentation layer (controllers) to use registered services in runtime, thus enabling the tester to easily decouple the service layer from the presentation layer and use a mock service to reduce the scope of the unit tests.

First, Unity was installed via NuGet:

Then, UnityConfig class was created. This class is responsible for registering the interfaces of the services that will be used by the controllers (in their constructors). The binding is done automatically in runtime by the Unity.Mvc5 library.

Finally, the Global.asax file was to be changed to include UnityConfig.RegisterComponents() method inside Application_Start.

The controller has to be changed to require the IProductService in the constructor. The service will be inserted by Unity (in production environment) or programmatically in the unit tests.

Useful references:

Unit Test

In order to approximate this project even further with a real-world scenario, a new project was created to allow the execution of unit tests and thus simulate a Test-Driven Development methodology, commonly used amongst IT departments in the industry today. POC_UnitTest project was created inside the solution, and references the presentation layer project and to the Common library were added.

Then, a MockProductService implementing the IProductService was created. This is the mock service that would be used during the tests instead of using the real service implementation (WCF) injected by Unity.

Finally, some unit tests were implemented using the 'AAA' unit test pattern (Arrange, Act, Assert).

The results of the tests can be seen in the Test Explorer tab.

Useful references:

Conclusion

This project demonstrated the differences when using MVC only to develop the presentation layer of a web application and when using some of the most popular javascript libraries, such as jQuery with Datatables and AngularJS. Additionally, some of the most common practices used in software development departments today were showcased, such as unit tests and dependency injection.

About

The goal of this project was to create an MVC project on Visual Studio to run a simple CRUD web application using a multitier architecture

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published