learning mvcpart 1 introduction to mvc architecture and separation of concerns

Upload: joao-pimentel

Post on 04-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 learning MVCPart 1 Introduction to MVC Architecture and Separation of Concerns

    1/3

    csharppulse.blogspot.in http://csharppulse.blogspot.in/2013/08/learning-mvc-part-1-introduction-to-mvc.html

    Learning MVC-Part 1 : Introduction to MVC Architecture and

    Separation of Concerns

    Introduction:

    Af ter having go ne through numerous of blogs and art icles, I came to a conclusion that very f ew of thegenuine writers have explained the topic fro m 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 almos t all the aspects o f MVC starting

    f rom creating simple app and connecting with the database with various Microsof t providers. Well be

    gradually moving forward 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 connect ing 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 Reposito ry Pattern and Unit Of Work pat tern in MVC Application with

    EntityFramework.

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

    http://csharppulse.blogspot.in/2013/09/learning-mvc-part-6-generic-repository.htmlhttp://csharppulse.blogspot.in/2013/09/learning-mvc-part-4-creating-mvc.htmlhttp://csharppulse.blogspot.in/2013/09/learning-mvc-part-4-creating-mvc.htmlhttp://csharppulse.blogspot.in/2013/09/learning-mvc-part-6-generic-repository.htmlhttp://csharppulse.blogspot.in/2013/09/learning-mvc-part-5repository-pattern.htmlhttp://csharppulse.blogspot.in/2013/09/learning-mvc-part-4-creating-mvc.htmlhttp://csharppulse.blogspot.in/2013/08/learning-mvc-part-3-creating-mvc.htmlhttp://csharppulse.blogspot.in/2013/08/learning-mvc-part-2-creating-mvc.htmlhttp://csharppulse.blogspot.in/2013/08/learning-mvc-part-1-introduction-to-mvc.htmlhttp://csharppulse.blogspot.in/2013/08/learning-mvc-part-1-introduction-to-mvc.htmlhttp://csharppulse.blogspot.in/
  • 8/13/2019 learning MVCPart 1 Introduction to MVC Architecture and Separation of Concerns

    2/3

    Part1: Introduction to MVC architecture and Separation of Concerns.

    Topics t o be covered:

    1. What does MVC mean.

    2. Understand MVC Architecture.

    3. Separation of Concerns

    Players:

    Model: The 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: The user interf ace that renders the model into a form of interaction.

    Controller: Handles a request f rom a view and updates the model that results a change in Models st ate.

    To implement MVC in .NET we need mainly three classes (View, Cont roller and the Model).

    MVC Archite cture:

    The choice of MVC comes when we go f or a so lution where separation of concerns, ease of

    maintainability and extensibility of an application matt ers a lot. As per the architecture given below, we can

    see the request -response f low of a MVC application.

    The 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 t o t he contro ller as per route, the contro ller

    communicates with model and passes t he populated model(entity) to View(front end), Views are populatedwith model propert ies, and are rendered on the browser, pass ing the response to browser t hrough IIS via

    controllers which invoked the particular View.

    Separation of Concern:

  • 8/13/2019 learning MVCPart 1 Introduction to MVC Architecture and Separation of Concerns

    3/3

    As per Wikipedia 'the process of breaking a co mputer program into dist inct f eatures that overlap in

    f unctionality as litt le as poss ible'. MVC design pattern aims to separate content f rom presentation and

    data-processing f rom content. Theoret ically well, but where do we see this in MVC? One is reasonably clear

    - between the data-processing (Model) and the rest o f the application.

    When we talk about Views and Contro llers, t heir ownership itself explains separation.The views are just t he

    presentation form of an application, it does not have to know specif ically about the requests coming fro m

    contro ller. The Model is independent o f View and Contro llers, it only holds business entities that can be

    passed to any View by contro ller as per need of exposing them to end user.The contro ller in independent

    of Views and Models, its sole purpose is to handle requests and pass it o n as per the routes def ined and

    as per need of rendering views.Thus our business entit ies(model), business logic(cont rollers) and

    presentation logic(views) lie in logical/physical layers independent o f 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 implementat ion of MVC.