Asp.net MVC 3 Convention over configuration 约定胜于配置

这个约定是我在Profession Asp.net MVC 3 这本书上看到写下的笔记,作为一个总结。因为原书是英文的,所以可能会有翻译不对的地方,我尽量使用原文。

MVC is designed around some sensible convention-based defaults that can be overridden as needed.This concept is commonly referred to as “Convention over configuration”.

MVC被设计用来遵循以约定为基础。

约定胜于配置在一些年前的Ruby on Rails 很流行,它最基本的定义是:

We know,by now,how to build a web application.Let’s roll that experience into the framework so we don’t have to configure absolutely everything,again.

我们知道,至少到目前为止,如何去创建一个Web程序。我们把我们的经验加入到框架中,我们就不必去配置任何必须的事情。

You can see this concept at work in asp.net MVC by taking a look at the three core directories that make the application work:

  • Controllers
  • Models
  • Views

You don’t have to set these folder names in the web.config file-----they are just expected to be there by convention.This saves you the work of having to edit an XML file like your web.config,for example ,in order to explicitly(显式的) tell the MVC engine.”You can find my views in the Views directory”-------it already knows.It’s convention.这就是约定

posted @ 2012-11-17 12:23  baidixing  阅读(1201)  评论(2编辑  收藏  举报