asp.net-mvc 中的控制器应该有多大
我看到了 asp.net-mvc 2 中区域的新功能。它引起了我的思考。我为什么需要这个?我阅读了一些用例,最后得出一个具体的结论:我的控制器应该有多大、范围有多广?
我应该尝试拥有许多小控制器吗?一个大控制器?
人们如何确定控制器数量的最佳位置?我认为我的可能太大了(这让我首先质疑区域,因为也许我的控制器名称实际上应该是一个区域并且有许多较小的控制器)
i see the new feature of areas in asp.net-mvc 2. it got me thinking. why would i need this? i did some reading on the use cases and it came down to a specific point to me around how big and how broad scope should my controllers should be?
should i try to have many little controllers? one big controller?
how do people determine the sweet spot for number of controllers? i think mine are maybe too large (which had me questioning areas in the first place as maybe my controller name should really be an area and have a number of smaller controllers)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢根据控制者负责的领域来考虑控制者。因此,您始终可以合并和拆分它们以找到平衡。
例如,您可以为域用户拥有一个巨型控制器。或者您可以将其分为用户/设置、用户/个人资料、用户/订单、用户/统计等区域。当它们增长时,您可以进一步将它们划分为用户/订购统计、用户/访问统计、用户/项目组统计等。
I like to think of controllers in terms of domain areas they are responsible for. As such, you can always merge and split them to find the balance.
For example, you can have one giant controller for the domain User. Or you could split it into areas like User/Settings, User/Profile, User/Orders, User/Statistics etc. When they grow you divide them further like User/OrderingStatistics, User/VisitStatistics, User/ItemGroupStatistics etc.