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.
[assembly: PreApplicationStartMethod(typeof(MvcApplication), “RegisterCustomModule”)]
But, before this let me show the snippet for the custom module which I have created here.
This is the simple snippet where in I am actually implementing “IHttpModule“. This is straight forward snippet. Here, at every HTTP Event it will just print the message “Item Logged Successfully“. Also, I have modified the global.asax file as well. Below is the snippet for the same.
With the above change in place, when I run the app, then it will produce following stuffs.
Then, Application_Start event will get triggered
At this stage, our custom module which we created would have got registered with our other existing modules like shown below.
Now, when I inspect the output window, it will produce the below result.
Since, this is HTTPModule, hence it will print the message number of times HTTP-Request happens. Here, we can see that message got printed successfully. I hope you would have liked this post. In the coming section, we will delve further.
Code Download Link:- https://github.com/rahulsahay19/MVCLifeCycle
2,192 total views, 1 views today