加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.net MVC项目结构

发布时间:2020-12-15 20:14:50 所属栏目:asp.Net 来源:网络整理
导读:我已经为我的新的asp.net mvc项目创建了以下项目结构,我曾经有一些反馈意见,如其他人如何构建他们的项目,如果我会改进我的… 这是我到目前为止 +Assets-+Images -+Scripts -+Stylesheets -+... 'More things like the above here+Controllers -+Support--+Ac
我已经为我的新的asp.net mvc项目创建了以下项目结构,我曾经有一些反馈意见,如其他人如何构建他们的项目,如果我会改进我的…

这是我到目前为止

+Assets
-+Images 
-+Scripts 
-+Stylesheets 
-+...              'More things like the above here
+Controllers 
-+Support
--+Actions         'Any custom action classes
--+Controllers     'Base controller classes
+Models
-+Domain           'Contains any class that specialise view specific domain logic
--+UrlProcessing   'Encoding/decoding business entities as URL parts 
--+...             'More things like the above here
-+Views            'Contains view models
--+Support
---+Views          'Base classes for any view models
+Support
-+Application      'Global application interface classes (i.e. class that wraps the function of the global asax)
-+Configuration    'Typed config classes
-+Helpers          'Where you put additional html helper classes,etc
-+Services
--+Bootstrap       'Tasks that run on mvc start-up that are specific to the MVC project
--+Inversion       'Specific IoC registration registrations for this project 
--+...             'More things like the above here
+Views
-+Home
-+Shared 
-+...              'More things like the above here

干杯安东尼

解决方法

我有类似的结构,有一些例外:
  1. Support is named Infrastructure (namespace for UI assembly usage only)
  2. IoC is in different project (project for globally used Infrastructure functionality). UI has StructureMaps Registry only with assembly names (IoC is initialized by convention). Approach kind a stolen from CodeCampServer source. Logging,configuration sections goes here too.
  3. Views/[ControllerName] has Partial subfolder which might be even more divided
    (this involves juggling with ViewEngine so it could find views/partial views).
  4. Views/[ControllerName] has LocalResources folder (with Partial subfolder)
  5. Haven’t added any subfolder under Controllers (…yet). I like to keep them clean and quite stupid.

还有一些例外,与模型有关:

  1. All business logic lives in Domain assembly,Domain.Model namespace with some help of Infrastructure layer for technical aspects.
  2. View models (i’m calling them ViewData) lives in UI assembly under ViewData folder,structured in folders similar as Views are. Picked approach from Kigg (except that i structure them per View like SearchViewData,sometimes even per partial view).

到目前为止,它工作得很好

注意,对于更复杂的网站,构造ViewData(我甚至以相同的方式构造我的javascript,View == JS文件,其中包含名为[ViewName]的对象下的所有内容)可能不被接受.

哦…和=> folder ==我的命名空间.我想这是一个很好的做法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读