MVC是编写asp.net应用程序的最佳方式吗?

时间:2022-08-26 20:50:16

update: I know there is no one best way to do everything. Sorry for not saying that right off. In the context of the data-access tutorials, if you had to do the project he did in that tutorial, would you do what he did or would use use MVC, if you had to choose one of them?

更新:我知道没有一种方法可以做任何事情。很抱歉没有说出来。在数据访问教程的上下文中,如果你必须完成他在该教程中所做的项目,你会做他做过或将使用MVC的项目,如果你必须选择其中一个吗?

Update: Is MVC the more appropriate way to program asp.net applications, instead of the tutorials found here:

更新:MVC是编程asp.net应用程序的更合适的方式,而不是这里的教程:

http://www.asp.net/Learn/data-access/

http://www.asp.net/Learn/data-access/

Original:

原版的:

I ask, because I initially learned about MVC with Java applications, then things like RoR, and Django. These other projects and companies spoke as if MVC had been around for a very long time, and from what I found out it had. Then Microsoft started putting MVC into the .net framework.

我问,因为我最初了解了使用Java应用程序的MVC,然后是RoR和Django。这些其他项目和公司说好像MVC已经存在了很长时间,并且从我发现它已经发现了。然后微软开始将MVC放入.net框架。

I ask because I don't know how to design things very well and thought I was doing well to emulate what's on the asp.net site with Scott Mitchell's tutorial. I thought that creating abstract layers in a BLL was the way to go until I found out about MVC and now asp.net's MVC.

我问,因为我不知道如何设计得很好,并且认为我在使用Scott Mitchell的教程模拟asp.net网站上的内容时效果很好。我认为在BLL中创建抽象层是一种方法,直到我发现MVC和现在的asp.net的MVC。

I honestly don't know what the "right" way is to do things. I just create what I need, but I can't help feel like I am missing something.

老实说,我不知道“正确”的做法是什么。我只是创造了我需要的东西,但我不禁觉得我错过了什么。

Is MVC the correct way to start doing things in large projects, specifically I mean MVC and ASP.NET, but could just as well mean PHP and one of their MVC frameworks.

MVC是在大型项目中开始做事的正确方法,特别是我的意思是MVC和ASP.NET,但也可以表示PHP和他们的MVC框架之一。

I'd like to settle on a standard way of doing things...for now anyway.

无论如何,我现在想采取一种标准的做事方式......

And, out of curiosity, why did Microsoft only now start doing MVC?

而且,出于好奇,为什么微软现在才开始做MVC?

UPDATE: Is MVC better than the current tutorial set on asp.net?

更新:MVC比asp.net上设置的当前教程更好吗?

I'm referring to the Scott Mitchell tutorials where he creates the BLL for abstraction. Or is that a linq question as well. I should have said that I understand the need for keeping logic and presentation separate but unsure the best way to do it. I was using the asp.net tutorials. It worked fine. Then I found out the rest of the world, as I saw it anyway, was using MVC. Then Microsoft started developing MVC, so to me the other method seems obsolete and the wrong way to do things.

我指的是Scott Mitchell教程,他在那里创建了抽象BLL。或者这也是一个linq问题。我应该说,我理解保持逻辑和表示分离的必要性,但不确定最好的方法。我正在使用asp.net教程。它工作正常。然后我发现世界其他地方,正如我所看到的那样,正在使用MVC。然后微软开始开发MVC,所以对我来说,另一种方法似乎已经过时并且做错了。

8 个解决方案

#1


18  

No, it's not the only best way to do things.

不,这不是唯一最好的做事方式。

MVC is just a design pattern. The goal of all design patterns is simplicity. So as long as it makes your design simpler, go with it. If it makes things more complex for your specific application, try a different approach.

MVC只是一种设计模式。所有设计模式的目标都是简单。因此,只要它使您的设计更简单,就可以使用它。如果它使您的特定应用程序更复杂,请尝试不同的方法。

Unfortunately, some people think if they see a pattern, they should use it. It's just not true. Design patterns don't inherently make your application better. They are not an end. They are a means to an end (which is simplicity). So you should use them only if they are worth it.

不幸的是,有些人认为如果他们看到一种模式,他们应该使用它。这不是真的。设计模式本身并不能使您的应用程序更好。他们不是目的。它们是达到目的的手段(简单)。因此,只有在它们值得的时候才应该使用它们。

In my opinion, over-architecting things without a good reason is worse than writing code without any specific design.

在我看来,没有充分理由过度构建事物比编写没有任何特定设计的代码更糟糕。

EDIT: Regarding ASP.NET MVC: I have a negative personal bias toward ASP.NET Web forms. Before MVC, I did most of the dynamic aspects of advanced projects by writing custom handlers to have fine grained control over the HTML. Web Forms make Web development very easy but they have particularly a couple things that are good but sometimes are problematic. The first of which is ViewState and the second is complex WebControl architecture. Don't get me wrong. Those are signs of brilliance of ASP.NET. I haven't seen a single platform for Web development as easy as ASP.NET Web Forms and this is only because of great WebControl support which requires ViewState. However, in some projects, you want to have precise control on rendered HTML (specially when you have some client-side logic). You also want to make server side code maintainable in large projects. In those areas, ASP.NET MVC really shines. But I think ASP.NET Web Forms will remain a great technology where it's more applicable. After all, as I said regarding design patterns in general, you should carefully evaluate your design to see which one better fits your needs.

编辑:关于ASP.NET MVC:我对ASP.NET Web表单有负面的个人偏见。在MVC之前,我通过编写自定义处理程序来对HTML进行细粒度控制,从而完成了高级项目的大部分动态方面。 Web窗体使Web开发变得非常容易,但它们特别有一些很好但有时会有问题的东西。第一个是ViewState,第二个是复杂的WebControl架构。别误会我的意思。这些都是ASP.NET的辉煌迹象。我没有看到像Web Web Forms一样简单的Web开发平台,这只是因为WebControl支持需要ViewState。但是,在某些项目中,您希望对呈现的HTML进行精确控制(特别是当您有一些客户端逻辑时)。您还希望在大型项目中维护服务器端代码。在这些领域,ASP.NET MVC真的很棒。但我认为ASP.NET Web Forms仍然是一种更适用的优秀技术。毕竟,正如我所说的关于设计模式一般,你应该仔细评估你的设计,看看哪一个更适合你的需求。

Specifically, about data access, MVC usually requires more code than Web Forms counterparts. For presenting tabular data (i.e where GridView is applicable), I think ASP.NET Web Forms is the easier way to accomplish things. However, most data driven Web apps are not just manipulating a table directly in a database. They have complex layout. * is a great example of this. It is certainly data driven, but ASP.NET MVC better suits it.

具体来说,关于数据访问,MVC通常需要比Web Forms对应的代码更多的代码。为了呈现表格数据(即GridView适用的地方),我认为ASP.NET Web Forms是更容易实现的方法。但是,大多数数据驱动的Web应用程序不仅仅是直接在数据库中操作表。它们的布局复杂。 *就是一个很好的例子。它肯定是数据驱动的,但ASP.NET MVC更适合它。

#2


8  

There is no "right" way to do things without knowing what "things" are. MVC is a design pattern that solves a specific common problem - separation of presentational and domain logic. Every design pattern is a commonly accepted "good" solution to a specific problem.

在不知道“事物”是什么的情况下,没有“正确”的做法。 MVC是一种解决特定常见问题的设计模式 - 表示逻辑和域逻辑的分离。每种设计模式都是针对特定问题的普遍接受的“好”解决方案。

Those solutions, combined with knowledge and experience are building blocks for a good design. The "right" way to do things is to study your problem domain, research on possible solutions and apply the set of solutions that work best to solve it. Making mistakes is a part of the process as well, so don't be afraid to experiment and then refactor with rigor until you reach the solution that serves you best.

这些解决方案结合知识和经验是良好设计的基石。 “正确”的做事方式是研究您的问题领域,研究可能的解决方案并应用最有效解决方案的解决方案。犯错也是这个过程的一部分,所以不要害怕进行实验,然后严格重构,直到找到最适合你的解决方案。

#3


3  

MVC is the worst way to develop applications, except for all other ways that have been tried. :-)

MVC是开发应用程序的最糟糕方式,除了已经尝试过的所有其他方法。 :-)

Joking aside, MVC is one application design that encourages us not to write spaghetti code. It's a guideline that reminds us to keep business code separate from presentation code. This is very helpful as the application gets more complex.

开玩笑说,MVC是一种鼓励我们不要写意大利面条代码的应用程序设计。这是一个提醒我们将业务代码与表示代码分开的指南。随着应用程序变得更加复杂,这非常有用。

There are other variations that achieve that same benefit, but are not strictly the same as MVC. Presentation-abstraction-control (PAC) is one example.

还有其他变体可以实现同样的好处,但与MVC并不完全相同。表示 - 抽象 - 控制(PAC)就是一个例子。

As for why Microsoft is so late in adopting MVC, I'm not surprised that they are. They are pretty well-known (at least in recent years) for being conservative instead of innovative. They prefer to let other smaller companies take the risks in an unproven market, then they learn from the mistakes, churn out an overengineered competitor solution, and dominate through marketing.

至于为什么微软采用MVC这么晚,我对它们并不感到惊讶。它们因保守而非创新而闻名(至少近年来)。他们更愿意让其他小公司在未经证实的市场中承担风险,然后他们从错误中吸取教训,制定一个过度设计的竞争对手解决方案,并通过营销主导。

Example: Microsoft Internet Explorer was considered to be a latecomer to the browser market. Netscape had become very popular, leading the way in providing a platform for people to view HTML. Once the amount of HTML content on the Internet was at a useful level, Microsoft belched up their onomatopoeic "IE" product and quickly captured an overwhelming market share.

示例:Microsoft Internet Explorer被认为是浏览器市场的后来者。 Netscape已经变得非常受欢迎,在为人们提供查看HTML的平台方面处于领先地位。一旦互联网上的HTML内容量处于有用的水平,微软就会打造出他们的拟声“IE”产品,并迅速占据了压倒性的市场份额。

#4


1  

MVC is just one way of doing things. I like it because it helps to promote extensibility and is structured to allow testing and code reuse. There is no silver bullet, one true way to do everything but I use it quite often.

MVC只是一种做事方式。我喜欢它,因为它有助于提升可扩展性,并且结构允许测试和代码重用。没有银弹,一种真正的方法来做所有事情,但我经常使用它。

In regard to Microsoft, I would say that they adopted the pattern as an alternative to WebForms development for the reasons I mentioned above. I would recommend looking at Rob Conery's MVC Storefront and kind of play around with the examples to see how it works for you.

关于微软,我会说他们采用这种模式作为WebForms开发的替代方案,原因如上所述。我建议看一下Rob Conery的MVC店面,并通过这些示例来了解它是如何运作的。

#5


1  

There is no "best" way to code things. It depends on the application in question; sometimes MVC is the right choice, and sometimes it's not. A good developer is able to weigh his/her options and choose the one that's best suited for a task at hand, instead of just going with the method du jour

没有“最好”的方法来编写代码。这取决于有问题的申请;有时MVC是正确的选择,有时它不是。一个优秀的开发人员能够权衡他/她的选择,并选择最适合手头任务的选项,而不是仅仅使用方法du jour

#6


1  

If MVC solves the Primary Technical Imperative of managing complexity in your application then it may be a good solution, but it is by no means the only solution.

如果MVC解决了管理应用程序复杂性的主要技术要求,那么它可能是一个很好的解决方案,但它绝不是唯一的解决方案。

#7


1  

MVC is one of any number of design patterns. Whether it's the best technologically, or the simplest, or for what types of projects it's appropriate, are are all arguable (see other SO threads). In any case, few would argue against the prevailing consensus that for most cases, it's "Good Enough".

MVC是众多设计模式中的一种。无论是最好的技术,还是最简单的,或者适合的项目类型,都是有争议的(参见其他SO线程)。在任何情况下,很少有人会反对普遍的共识,即在大多数情况下,它是“足够好”。

But it has the undeniable benefit that a lot of people use it, on a lot of different platforms.

但它有很多人在许多不同平台上使用它的无可否认的好处。

So if you want to use a methodology that is likely to be around a while; or you don't want to depend on one vendor for support and extension and refinement; or you work in a group that would like to grow by hiring people from various backgrounds who will grok a shared methodology quickly; or you would like to maximize your opportunities to move on if you need to, then MVC is one of the very best ways to support those goals.

因此,如果您想使用可能会持续一段时间的方法;或者你不想依赖一个供应商的支持和扩展和改进;或者你是一个希望通过雇佣来自不同背景的人来增长的团队,他们会迅速找到共同的方法;或者如果您需要,您希望最大化继续前进的机会,那么MVC是支持这些目标的最佳方式之一。

#8


1  

MVC being "Better" or "Worse" pattern is relative to the project.

MVC是“更好”或“更糟”的模式是相对于项目。

#1


18  

No, it's not the only best way to do things.

不,这不是唯一最好的做事方式。

MVC is just a design pattern. The goal of all design patterns is simplicity. So as long as it makes your design simpler, go with it. If it makes things more complex for your specific application, try a different approach.

MVC只是一种设计模式。所有设计模式的目标都是简单。因此,只要它使您的设计更简单,就可以使用它。如果它使您的特定应用程序更复杂,请尝试不同的方法。

Unfortunately, some people think if they see a pattern, they should use it. It's just not true. Design patterns don't inherently make your application better. They are not an end. They are a means to an end (which is simplicity). So you should use them only if they are worth it.

不幸的是,有些人认为如果他们看到一种模式,他们应该使用它。这不是真的。设计模式本身并不能使您的应用程序更好。他们不是目的。它们是达到目的的手段(简单)。因此,只有在它们值得的时候才应该使用它们。

In my opinion, over-architecting things without a good reason is worse than writing code without any specific design.

在我看来,没有充分理由过度构建事物比编写没有任何特定设计的代码更糟糕。

EDIT: Regarding ASP.NET MVC: I have a negative personal bias toward ASP.NET Web forms. Before MVC, I did most of the dynamic aspects of advanced projects by writing custom handlers to have fine grained control over the HTML. Web Forms make Web development very easy but they have particularly a couple things that are good but sometimes are problematic. The first of which is ViewState and the second is complex WebControl architecture. Don't get me wrong. Those are signs of brilliance of ASP.NET. I haven't seen a single platform for Web development as easy as ASP.NET Web Forms and this is only because of great WebControl support which requires ViewState. However, in some projects, you want to have precise control on rendered HTML (specially when you have some client-side logic). You also want to make server side code maintainable in large projects. In those areas, ASP.NET MVC really shines. But I think ASP.NET Web Forms will remain a great technology where it's more applicable. After all, as I said regarding design patterns in general, you should carefully evaluate your design to see which one better fits your needs.

编辑:关于ASP.NET MVC:我对ASP.NET Web表单有负面的个人偏见。在MVC之前,我通过编写自定义处理程序来对HTML进行细粒度控制,从而完成了高级项目的大部分动态方面。 Web窗体使Web开发变得非常容易,但它们特别有一些很好但有时会有问题的东西。第一个是ViewState,第二个是复杂的WebControl架构。别误会我的意思。这些都是ASP.NET的辉煌迹象。我没有看到像Web Web Forms一样简单的Web开发平台,这只是因为WebControl支持需要ViewState。但是,在某些项目中,您希望对呈现的HTML进行精确控制(特别是当您有一些客户端逻辑时)。您还希望在大型项目中维护服务器端代码。在这些领域,ASP.NET MVC真的很棒。但我认为ASP.NET Web Forms仍然是一种更适用的优秀技术。毕竟,正如我所说的关于设计模式一般,你应该仔细评估你的设计,看看哪一个更适合你的需求。

Specifically, about data access, MVC usually requires more code than Web Forms counterparts. For presenting tabular data (i.e where GridView is applicable), I think ASP.NET Web Forms is the easier way to accomplish things. However, most data driven Web apps are not just manipulating a table directly in a database. They have complex layout. * is a great example of this. It is certainly data driven, but ASP.NET MVC better suits it.

具体来说,关于数据访问,MVC通常需要比Web Forms对应的代码更多的代码。为了呈现表格数据(即GridView适用的地方),我认为ASP.NET Web Forms是更容易实现的方法。但是,大多数数据驱动的Web应用程序不仅仅是直接在数据库中操作表。它们的布局复杂。 *就是一个很好的例子。它肯定是数据驱动的,但ASP.NET MVC更适合它。

#2


8  

There is no "right" way to do things without knowing what "things" are. MVC is a design pattern that solves a specific common problem - separation of presentational and domain logic. Every design pattern is a commonly accepted "good" solution to a specific problem.

在不知道“事物”是什么的情况下,没有“正确”的做法。 MVC是一种解决特定常见问题的设计模式 - 表示逻辑和域逻辑的分离。每种设计模式都是针对特定问题的普遍接受的“好”解决方案。

Those solutions, combined with knowledge and experience are building blocks for a good design. The "right" way to do things is to study your problem domain, research on possible solutions and apply the set of solutions that work best to solve it. Making mistakes is a part of the process as well, so don't be afraid to experiment and then refactor with rigor until you reach the solution that serves you best.

这些解决方案结合知识和经验是良好设计的基石。 “正确”的做事方式是研究您的问题领域,研究可能的解决方案并应用最有效解决方案的解决方案。犯错也是这个过程的一部分,所以不要害怕进行实验,然后严格重构,直到找到最适合你的解决方案。

#3


3  

MVC is the worst way to develop applications, except for all other ways that have been tried. :-)

MVC是开发应用程序的最糟糕方式,除了已经尝试过的所有其他方法。 :-)

Joking aside, MVC is one application design that encourages us not to write spaghetti code. It's a guideline that reminds us to keep business code separate from presentation code. This is very helpful as the application gets more complex.

开玩笑说,MVC是一种鼓励我们不要写意大利面条代码的应用程序设计。这是一个提醒我们将业务代码与表示代码分开的指南。随着应用程序变得更加复杂,这非常有用。

There are other variations that achieve that same benefit, but are not strictly the same as MVC. Presentation-abstraction-control (PAC) is one example.

还有其他变体可以实现同样的好处,但与MVC并不完全相同。表示 - 抽象 - 控制(PAC)就是一个例子。

As for why Microsoft is so late in adopting MVC, I'm not surprised that they are. They are pretty well-known (at least in recent years) for being conservative instead of innovative. They prefer to let other smaller companies take the risks in an unproven market, then they learn from the mistakes, churn out an overengineered competitor solution, and dominate through marketing.

至于为什么微软采用MVC这么晚,我对它们并不感到惊讶。它们因保守而非创新而闻名(至少近年来)。他们更愿意让其他小公司在未经证实的市场中承担风险,然后他们从错误中吸取教训,制定一个过度设计的竞争对手解决方案,并通过营销主导。

Example: Microsoft Internet Explorer was considered to be a latecomer to the browser market. Netscape had become very popular, leading the way in providing a platform for people to view HTML. Once the amount of HTML content on the Internet was at a useful level, Microsoft belched up their onomatopoeic "IE" product and quickly captured an overwhelming market share.

示例:Microsoft Internet Explorer被认为是浏览器市场的后来者。 Netscape已经变得非常受欢迎,在为人们提供查看HTML的平台方面处于领先地位。一旦互联网上的HTML内容量处于有用的水平,微软就会打造出他们的拟声“IE”产品,并迅速占据了压倒性的市场份额。

#4


1  

MVC is just one way of doing things. I like it because it helps to promote extensibility and is structured to allow testing and code reuse. There is no silver bullet, one true way to do everything but I use it quite often.

MVC只是一种做事方式。我喜欢它,因为它有助于提升可扩展性,并且结构允许测试和代码重用。没有银弹,一种真正的方法来做所有事情,但我经常使用它。

In regard to Microsoft, I would say that they adopted the pattern as an alternative to WebForms development for the reasons I mentioned above. I would recommend looking at Rob Conery's MVC Storefront and kind of play around with the examples to see how it works for you.

关于微软,我会说他们采用这种模式作为WebForms开发的替代方案,原因如上所述。我建议看一下Rob Conery的MVC店面,并通过这些示例来了解它是如何运作的。

#5


1  

There is no "best" way to code things. It depends on the application in question; sometimes MVC is the right choice, and sometimes it's not. A good developer is able to weigh his/her options and choose the one that's best suited for a task at hand, instead of just going with the method du jour

没有“最好”的方法来编写代码。这取决于有问题的申请;有时MVC是正确的选择,有时它不是。一个优秀的开发人员能够权衡他/她的选择,并选择最适合手头任务的选项,而不是仅仅使用方法du jour

#6


1  

If MVC solves the Primary Technical Imperative of managing complexity in your application then it may be a good solution, but it is by no means the only solution.

如果MVC解决了管理应用程序复杂性的主要技术要求,那么它可能是一个很好的解决方案,但它绝不是唯一的解决方案。

#7


1  

MVC is one of any number of design patterns. Whether it's the best technologically, or the simplest, or for what types of projects it's appropriate, are are all arguable (see other SO threads). In any case, few would argue against the prevailing consensus that for most cases, it's "Good Enough".

MVC是众多设计模式中的一种。无论是最好的技术,还是最简单的,或者适合的项目类型,都是有争议的(参见其他SO线程)。在任何情况下,很少有人会反对普遍的共识,即在大多数情况下,它是“足够好”。

But it has the undeniable benefit that a lot of people use it, on a lot of different platforms.

但它有很多人在许多不同平台上使用它的无可否认的好处。

So if you want to use a methodology that is likely to be around a while; or you don't want to depend on one vendor for support and extension and refinement; or you work in a group that would like to grow by hiring people from various backgrounds who will grok a shared methodology quickly; or you would like to maximize your opportunities to move on if you need to, then MVC is one of the very best ways to support those goals.

因此,如果您想使用可能会持续一段时间的方法;或者你不想依赖一个供应商的支持和扩展和改进;或者你是一个希望通过雇佣来自不同背景的人来增长的团队,他们会迅速找到共同的方法;或者如果您需要,您希望最大化继续前进的机会,那么MVC是支持这些目标的最佳方式之一。

#8


1  

MVC being "Better" or "Worse" pattern is relative to the project.

MVC是“更好”或“更糟”的模式是相对于项目。