⬆️ ⬇️

ASP.NET MVC Framework - Put the Dots

The first point is put in the question “Should I switch to the MVC Framework and why?”



With this article I would like to open a series of articles about the MVC Framework. Lately, I have been working very closely with him and with his insides, and I have accumulated several thoughts, interesting observations and knowledge that I would like to share. If you are an ASP.NET programmer and are not familiar or are not familiar with the MVC Framework, then I would like to believe my articles will help you understand this tool better. In any case, even if you know the subject very well, I think we will have something to discuss with you in the comments on each raised topic.



So, the first introductory note is devoted to the question of the need to use or transition to the MVC Framework from the classic ASP.NET. This question is not an easy one and the answer that I will give will not repeat the sample recommendations and comparisons that you can find on the Internet. On the contrary, I would like to turn the point so that you look at the problem from the other side.



Why you don't need MVC Framework



Consider first why you do not need the MVC Framework:

')

* You do not need the MVC Framework if you think that it is better than classic ASP.NET. If you think so, then you know ASP.NET badly, you still have room to grow and what to learn. If you think that the MVC Framework is better than ASP.NET, it means that you did not like ASP.NET and did not understand the full charm of its ideology. In this case, it is too early for you to go to the MVC Framework. It’s simply nowhere to switch to a new framework if you don’t have a proper understanding and love for the basic mechanism. Learn ASP.NET, understand why and how everything is arranged there. You don't need the MVC Framework;



* You do not need the MVC Framework in order to use the MVC pattern. In fact, MVC has nothing to do with a particular library. The MVC Framework is just an implementation of a pattern that no one bothers you to create and use yourself in classic ASP.NET. Try it, it is not difficult. You do not need the MVC Framework if the only reason is MVC;



* You do not need the MVC Framework if you want to get rid of the viewstate. The MVC Framework is not intended for the purpose of “getting rid of the viewstate”. If you want to get rid of the viewstate, then learn how this mechanism works. Why it is and what it serves. I assure you, the viewstate in skillful hands is very useful. And the large and heavy viewstate pages are the result of poor design or lack of knowledge of the developer;



* You do not need the MVC Framework if you want to get rid of the automatic generation of identifiers. History repeats itself. Everything related to the viewstate is applicable to the autogeneration of id for html markup elements. If you understand how and why identifiers are generated, you will no longer want to get rid of them. In addition, in ASP.NET 4.0 you have the opportunity to more flexibly manage generation, and this is another reason why you don’t need the MVC Framework;



* You do not need the MVC Framework if you want to “get complete control over the markup.” In classic ASP.NET, the developer also has full control over the markup and the desire to get something else is an obvious sign that the developer does not understand ASP.NET well. Only by understanding how ASP.NET works with markup and how it handles requests, can the classical model be compared with the MVC Framework model. If you are well aware of how both of these mechanisms work, then the requirement of this paragraph will disappear by itself. You don't need the MVC Framework to manage markup;



* You do not need the MVC Framework if you want a readable URL. The routing mechanism that allows you to represent readable URLs is part of ASP.NET, but not the inner part of the MVC Framework, so you can use routing and create readable URLs in classic ASP.NET, you do not need the MVC Framework for this.



Hope you disagree with some of these points. This is good, perhaps my theses will make you take a different look at the question.



Why do you need MVC Framework



Consider the reasons why you need the MVC Framework:



* You need the MVC Framework because you want to cover a significant or all part of the code with unit tests. This is a worthy reason for the transition to the MVC Framework, its model suggests that any part of the framework can be exposed to testing at any stage. Whereas in classic ASP.NET, the postback callback mechanism has often made it difficult to write tests;



* You need MVC Framework if most of your code is not part of ASP.NET. This code is client-side javascript and partly AJAX. When the foundation was laid for ASP.NET client optimization and very little attention was paid to client-side code, at that time there was no AJAX or Web 2.0 concept. Times have changed, classic ASP.NET is also changing, it has a lot of tools to support the AJAX functionality, but still creating a powerful client code remains a difficult task. If you have a large amount of code on the client side, maybe even as much on the server side, then you need the MVC Framework, it will facilitate your work;



* and the main and main reason why you need the MVC Framework is absolute extensibility. In this regard, the MVC Framework is really a framework that can be filled as you need. You can make the following comparison: classic ASP.NET is a picture drawn by a master, while the MVC Framework is a sketch, a sketch that you sketch, complete, and give to you yourself. In the MVC Framework, you can redefine the mechanism at any stage from processing a request to sending a result.



Switching to the MVC Framework should not be a search for getting rid of “problems”. Look at the problems more closely and you will see that they are all solved within the framework of the classic ASP.NET model. Many people do not understand that the main strength and power, then why use the MVC Framework is not the “flaws” of the classic ASP.NET model, which in most cases stem from a poor understanding of the subject. The power of the MVC Framework is in its capabilities and potential for extensibility. The MVC Framework is the constructor you need to wish after being fully saturated with proven tools. If you are faced with a problem when ASP.NET mechanisms are not enough for you, when you are constrained by the framework of the proposed model, which cannot be expanded or modified, then only you really need MVC Framework. Any other cases, attempts to get rid of “shortcomings” or “transition to the MVC pattern” are insufficient reasons for the need to switch to MVC and for the most part are an erroneous point of view on the question.



That is all I would like to say on the question “Should I switch to the MVC Framework and why?”. I hope that the point that I put in this article will interest you and make you think or look at the question from a different angle. In the next part I will try to put an end to the question “How does the MVC Framework mechanism work?”.



Progg it

Source: https://habr.com/ru/post/63138/



All Articles