Introduction
ASP.NET MVC is a web development framework that combines the effectiveness and tidiness of model-view-controller (MVC) architecture.
Drawbacks of ASP.NET Webforms
- View State Weight – large blocks of data transferred between client and server on every request creating slower response time and increasing bandwidth.
- Page life cycle – connecting client-side events with server-side event handler code, some controls fail during the runtime without any view state errors
- False sense of separation of concerns – developers were encouraged to mix presentation code with application logic in the same code behind classes
- Limited control over HTML – server controls render themselves as HTML, sometimes fail to meet Web standards, difficult to access ID attribute with JavaScript
- Leaky abstraction – difficult to implement custom behaviours as web form tries to hide HTML and HTTP
- Low testability – tightly coupled architecture is difficult for unit testing also integration test
Importance of MVC Framework
Separation of Concern (SoC)
Is a software concept that separates program into different sections or concerns. By doing the separation each can encapsulate information that can be developed and updated independently.
Loose coupling is an architectural approach in which the designer seeks to limit the amount of inter dependencies between various parts of a system.
By reducing inter dependencies, changes to one area of an application are less likely to affect another area.
Repository pattern
Is highly useful in unit testing because it enables you to substitute the actual data connection with a mocked repository that provides well-known data.
The persistence layer deals with persisting (storing and retrieving) data from a datastore, just like the repository.
When using repository you instantiate the interface rather the class. This enables you to use data connection when doing work on the mock repository during testing.
To implement a repository you can create a global repository for all the data, a repository for each entity or some combination.
Live as if you were to die tomorrow. Learn as if you were to live forever.. -Mahatma Gandhi