Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

csharppulse .blo gspo t .

in

http://csharppulse.blo gspo t.in/2013/08/learning-mvc-part-1-intro ductio n-to -mvc.html

Learning MVC-Part 1 : Introduction to MVC Architecture and Separation of Concerns


Introduction :

Af ter having gone through numerous of blogs and articles, I came to a conclusion that very f ew of the genuine writers have explained the topic f rom basics to its details in a f ull-f ledged way with a working application. My ef f ort in this MVC articles series would be to cover almost all the aspects of MVC starting f rom creating simple app and connecting with the database with various Microsof t providers. Well be gradually moving f orward part by part to understand and practically implement all the scenarios. Road Map:

1. Part1: Introduction to MVCarchitecture and Separation of Concerns. 2. Part 2: Creating MVC Application f romscratch and connecting it with database using LINQ to SQL. 3. Part 3: Connecting the MVC Application with the help of EntityFramework DB-First approach. 4. Part 4: Connecting the MVC Application with the help of EntityFramework Code-First approach. 5. Part 5: Implementing Repository Pattern in MVC Application with EntityFramework. 6. Part 6: Implementing a generic Repository Pattern and Unit Of Work pattern in MVC Application with EntityFramework.

All set, now we can start our journey with Part1.

Part1: Introduction to MVC architecture and Separation of Concerns. Topics to be covered: 1. 2. 3. What does MVC mean. Understand MVC Architecture. Separation of Concerns

Players: Model: T he business entity on which the overall application operates. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specif ically mention the data access layer because it is understood to be encapsulated by the Model. View: T he user interf ace that renders the model into a f orm of interaction. Controller : Handles a request f rom a view and updates the model that results a change in Models state. To implement MVC in .NET we need mainly three classes (View, Controller and the Model). MVC Architecture:

T he choice of MVC comes when we go f or a solution where separation of concerns, ease of maintainability and extensibility of an application matters a lot. As per the architecture given below, we can see the request-response f low of a MVC application.

T he architecture is self explanatory in itself . Browser as usual sends a request to IIS,IIS searches f or the route def ined in MVC application and passes request to the controller as per route, the controller communicates with model and passes the populated model(entity) to View(f ront end), Views are populated with model properties, and are rendered on the browser, passing the response to browser through IIS via controllers which invoked the particular View. Separation of Concern:

As per Wikipedia 'the process of breaking a computer program into distinct f eatures that overlap in f unctionality as little as possible'. MVC design pattern aims to separate content f rom presentation and data-processing f rom content. T heoretically well, but where do we see this in MVC? One is reasonably clear - between the data-processing (Model) and the rest of the application. When we talk about Views and Controllers, their ownership itself explains separation.T he views are just the presentation f orm of an application, it does not have to know specif ically about the requests coming f rom controller. T he Model is independent of View and Controllers, it only holds business entities that can be passed to any View by controller as per need of exposing them to end user.T he controller in independent of Views and Models, its sole purpose is to handle requests and pass it on as per the routes def ined and as per need of rendering views.T hus our business entities(model), business logic(controllers) and presentation logic(views) lie in logical/physical layers independent of each other. Conclusion: Now we know why and where to use MVC, in another part of learning MVC well be creating a MVC application f rom scratch, exploring the practical implementation of MVC.

You might also like