Hi Friends, In this section, I am going to talk about the tools which I am using on regular basis to really make the app fast, robust, fluid and also which makes developer life easy going by making them more efficient while coding.
In this section, we will continue from the last section and the see the next segment of Action Execution Process. Here, in this case we will see Filters in action. Therefore, before the action method chosen, the Authentication and Authorization filter runs. Filters are nothing but MVC components to inject extra logic in between the MVC pipeline.Therefore, first authentication filter runs and if it succeeds then it will go to Authorization filter otherwise it will again ask user to re-authenticate. However, authorization is the filter which says are you allowed to access particular thing or not.
In this section, we will look at Action Execution event in the MVC life Cycle. Once, controller gets initialized then action invoker has to take decision saying which method to invoke and this piece is done by Action Invoker in the life cycle. Action Invoker based on different method signatures present in controller identifies the exact method to be invoked.
In the above snippet, there are two about methods. In this case, it has become ambiguous for action invoker to figureout to choose which method to pick and hence produced below error. However, this can be easily fixed by applying any HTTP Verbs or Action Selectors like shown below.
In this section, we are going to see how Controllersare created and initialized.Basically, controllers does nothing but implement IController interface. IController defines one important method called Execute(). Also, it is important to note that this method is entirely generic which means you can build your controller in a more custom way specific to particular requirement. However, MVC is very powerful framework wherein all the concerns are already addressed. But, you can extend the default implementation for any specific need.
In this section, we will continue from the previous point and delve further into MVC components. Here, in this case we will look at building custom handler. HTTPHandlers implement IHTTPHandler and generate a response to HTTP-Request. Therefore, we first need to create the Handler and then register the same with the application either through code or via config file. Now, IHTTPHandler exposes two properties.
In this section, we are going to delve further around MVC Life Cycle. In the previous section, we have seen basic flow of MVC. However, let us consider the case, wherein you need to inject your custom module and wants to do logging extensively. In this kind of situation you want to execute some custom codes before actually the application starts. In order to achieve this kind of scenario, you need to make use of “PreApplicationStartMethod” @ assembly level. Below is the actual line of code of registering your custom module at PreApplicationStartMethod level.
In this section, I am going to describe MVC Life Cycle. If you are an MVC developer, then this entire flow should be in your DNA. This not only solves complex problem rather it also makes an app more robust, future proof, maintainable and testable. Below, I have pasted very high level diagram for the same. Therefore, without wasting time, let us get started.