In this video, the instructor introduces the fundamentals of the ASP.NET MVC framework, the Model-View-Controller architectural pattern, and the request life cycle.
- [Instructor] Before we explore the request life cycle, let's take a moment to review a couple of important points about asp.net MVC. This framework is based on the model-view- controller architecture pattern. The view is what the user sees. It's separated from the model, which is a class that represents data and also handles business logic for the application. The controller manages the interaction between the model and the view.
This design pattern provides separation of concerns because it separates the presentation from the business layer. The view knows nothing about the controller, and the model doesn't know anything about the view. This limits the interdependencies between the different parts of the system. Loose coupling is a term you might see that describes this kind of approach. The result is that our applications are more maintainable and testable by adhering to separation of concerns and reducing interdependencies, we end up building a more stable system.
Asp.net MVC was also developed to be extendable. Every major feature can be extended and customized, offering you a lot of flexibility. We've reviewed some of the highlights of the MVC framework. Now let's take a high level look at the lifecycle of an MVC request. It involves a sequence of steps that get repeated for every request. We'll cover each step in detail as we progress through this course.
It all starts when an http request is received from a client. The incoming request is matched to a predefined route during the routing step. The request gets processed by the http application pipeline. In this processing stage, the controller is created and initialized. The next major step is to find and invoke the right action method of the controller. This is when the data in the http request gets mapped to the action using model binding.
After the action is executed, the results are prepared to send back to the client. This step is called result execution and happens at the end of request processing. Action results send information back to the client through the http response. How this information is formatted can vary. It's usually sent back as html through a view or a partial view, but action results can also return other formats like json data.
Why is it important to learn about the request lifecycle, and what goes on behind the scenes? Well, you'll gain an in depth understanding of the entire flow, starting from when a request is made to when the response is sent back to the client. Like I mentioned earlier, the MVC framework is designed to be extensible. By understanding what happens at each step along the way, you can override the default behavior and customize it for your application.
You'll know the role of each lifecycle stage and where you can write your own code to have the desired effect.
- Fundamentals of the request life cycle
- Designing and implementing HTTP modules and handlers
- Choosing between handlers and modules
- Understanding route handlers
- Configuring convention-based routing
- ASP.NET MVC attribute routing
- Creating a custom controller factory
- Defining a custom dependency resolver
- Creating a custom view engine