一个理想的文件夹结构.NET MVC [英] An Ideal Folder Structure for .NET MVC
问题描述
当我在.NET Web表单开始我并没有太多的麻烦找到一个文件夹结构遵循自VS提供像APP_ code你的应用程序文件夹和应用程序大多数例子把血铅,DAL内有等。
When I started in .NET Webforms I didn't have much trouble finding a folder structure to follow since VS offered you application folders like "App_Code" and most app examples put "BLL", "DAL" inside there and so on.
但现在MVC中,我检查每例使用不同的结构,就像没有标准这个时候,我还没有找到一个很好的解决方案在谷歌左右。
But now in MVC, every example I check uses different structure, like no standards this time and I haven't found a good solution on Google or SO.
所以,也许我们可以分享我们如何组织我们的MVC项目,可以帮助别人,使自己的心意。这里是中小型项目中,我使用结构:
So, maybe we can share how we organize our MVC projects, may help others to make their own mind. Here is the structure for small to medium projects I use:
App_Data
Areas
Admin
Controllers
Models
Views
MyAccount
Controllers
Models
Views
Content
Images
Scripts
Styles
Controllers
HomeController.cs
Helpers
ExtensionMethods // I.e. based on HtmlHelper, use "helper" suffix
MenuHelper.cs // to be called as html.Menu()
Utilities.cs // Other generic (static) libraries, no suffix used
Models
ViewModels // for passing models to Views
RegisterViewModel.cs // use "ViewModel" suffix
Customer.cs // to extend models like adding Model Validation
Repositories
CustomerRepository.cs // use "Repository" suffix
Services
CustomerService.cs // use "Service" suffix, to move code away from controllers
Views
Home
Index.cshtml
Register.cshtml
Shared // Site Layouts (Master templates), also put partials here
SiteLayout.cshtml
什么你?
推荐答案
我发现它简化了部署有网站项目只包含内容(没有编译code)。
I have found it simplifies deployment to have the website project contain only content (no compiled code).
是这样的:
Web.Site项目
Content
Images
Css
Scripts
Views
web.config
和移动所有编译code到另一个项目:
And move all compiled code into another project:
Web项目
Controllers
Filters
Models
...
然后,您可以在Web.Site项目中的所有内容为需要进行部署,以及所有必需的组件将在Web.Site \\ bin中。
Then, you can treat everything within the Web.Site project as needing to be deployed, and all required assemblies will be in Web.Site\bin.
无论你是做简单的Xcopy部署,或使用维克斯建立MSI软件包,这会让生活变得更轻松。
Whether you are doing simple xcopy deployment, or using WiX to build an MSI package, this will make life a little easier.
这篇关于一个理想的文件夹结构.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!