为什么在ASP.NET MVC控制器基于域名? [英] Why are the controllers on ASP.NET MVC name-based?

查看:86
本文介绍了为什么在ASP.NET MVC控制器基于域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET MVC中,我们需要使用后缀控制器所​​有控制器。这似乎是不必要的限制 - 有一个技术原因呢?

In ASP.NET MVC, we're required to use the suffix "Controller" for all controllers. This seems unnecessarily restrictive - is there a technical reason for it?

我大多只是好奇,但能看到更加灵活的命名规则可以提高code的组织情况。难道不可能的控制器类的发现使用反射来搜索控制器派生类轻松完成?或者要求控制器类可以用一个标记 ControllerAttribute

I'm mostly just curious, but can see situations where more flexible naming rules could improve code organization. Couldn't the discovery of possible controller classes be easily made using reflection to search for Controller derived classes? Or require that controller classes be marked with a ControllerAttribute?

推荐答案

的MVC社区在很大程度上受到 Ruby on Rails的影响,其价值约定优于配置。只需命名事情持之以恒,应用程序可以使用零配置运行。

The MVC community is heavily influenced by Ruby on Rails, which values "convention over configuration". By just naming things consistently, the application can run with zero configuration.

这篇关于为什么在ASP.NET MVC控制器基于域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆