MVC3 - Where to place custom attribute classes

岁酱吖の 提交于 2019-12-22 02:00:56

问题


I am delving into custom validation attributes and am curious to know how others structure the projects. Where do you typically store custom attributes?

My first thought was to simply create a new folder and be done with it.

Any suggestions?


回答1:


I use 2 different approaches.

  1. Set up a common Class Library to store common validation that will be used on many MVC applications. Then reference this library from your MVC application. You can use http://dataannotationsextensions.org/ to view the source code on how to setup this project.

  2. Place them in folders as suggested by Darin. This folder would be used to store custom validation. If you app was used to keep golf scores a custom validation only to the application could have something to do with a handicap calculation or something specific.

Thanks,




回答2:


My first thought was to simply create a new folder and be done with it.

It would depend on the nature of those attributes and what thety are supposed to do. For example if they are validation attributes you could put them into a Validators folder. If they are action filters you could put them in the ActionFilters folder, etc... so your initial thought is correct. Personally I group those attributes based on their function and place them in a separate folder which indicates this function.



来源:https://stackoverflow.com/questions/7163698/mvc3-where-to-place-custom-attribute-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!